help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Lonewolf
Forum Commoner
Posts: 33
Joined: Tue May 06, 2003 9:36 pm

Post by Lonewolf »

ok how do i post more then 1 row, i try to go $sql = "SELECT memb_username, memb_first , memb_email , memb_pass , memb_last ,memb_extra,memb_id FROM ss_users WHERE memb_country=0,1,2,3";
and it says Invalid query: You have an error in your SQL syntax near '1,2,3,4,5,6' at line 1
what do i put, do i have to make a loop?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.mysql.com/doc/en/Comparison_ ... ml#IDX1142

Code: Select all

SELECT ... WHERE memb_country IN (0,1,2,3)
or in this case

Code: Select all

SELECT ... WHERE memb_country BETWEEN 0 AND 3
That most certainly will return more that one record. You have to fetch and process them one by one, e.g. by

Code: Select all

if (mysql_num_rows($result) == 0)
	echo 'no records match the conditions';
else
{
	while($row = mysql_fetch_array($result))
	{
		$first=$row['memb_username'];
		$last=$row['memb_last'];
		$id=$row['memb_id'];
		$country=$row['memb_country'];
		$first=$row['memb_first'];
		$email=$row['memb_email'];
		$extra=$row['memb_extra'];
		
		echo "<b>$first $last</b><br>extra:$extra<br>"; 
	}
}
Post Reply