Mysql query with two conditions where

I am doing automatic member scrolling. I have two mysql queries, I want to display those who have a photo and are ordered by last login. so in the first set I have no problems since I do it like

$sql=mysql_query("SELECT * 
                    FROM accounts 
                   WHERE avatar != '' 
                ORDER BY lastlogin DESC 
                   LIMIT 50");

It works great. But as the user scrolls and goes to the bottom of the page, I try to download the next set of 50 users ordered by the same filtering as above. Therefore, for this I do

$sql = mysql_query("SELECT * 
                      FROM accounts  
                     WHERE lastlogin < '$last_msg_id' 
                  ORDER BY lastlogin DESC 
                     LIMIT 50");

The above is used to search for the identifier of the last input ie the identifier of the 51st member from the last input. Now I need to filter out those elements that have a photo:

$sql = mysql_query("SELECT * 
                      FROM accounts 
                     WHERE avatar != '' 
                  ORDER BY lastlogin DESC 
                     LIMIT 50");

Tell me how I can combine these two queries, as I have no success.

+3
3

, , AND, :

  SELECT * 
    FROM accounts 
   WHERE lastlogin < '$last_msg_id' 
     AND avatar != '' 
ORDER BY lastlogin desc limit 50

, ?

+6

, ( ), 50 .

, , LIMIT . ( . MySQL SELECT.

LIMIT , - , - . , :

SELECT * FROM accounts LIMIT 0,50;   # Retrieves users 1-50
SELECT * FROM accounts LIMIT 50,50;  # Retrieves users 51-100
SELECT * FROM accounts LIMIT 100,50; # Retrieves users 101-150
                                     # etc.

, , T.J. ( AND, WHERE) - !

+3

- , phpmyadmin ... , .

-1

All Articles