SELECT查询只是SELECTING / CHECKING第一行,我如何SELECT / CHECK all

I have this simple query:

$q5 = "select listingid FROM userlisting WHERE userid = '$_SESSION[UserID]'";
$r5 = mysql_query($q5) or die(mysql_error());
$a5 = mysql_fetch_array($r5);

The userlisting table is a many to many relationship. It is used as a lookup table. Each userid can be associated with multiple listingids and vice versa.

Also in my file (a html template file) I have this code

if(!empty($_SESSION[UserID]) and $a5['listingid'] == $_GET['id']) :

So I am wanting to check if the listingid column in userlisting table = the id of the page (well, it is a property website and it is the id of the property). As each user can be associated with many listingids I need to be able to check multiple rows. But for some reason it only checks the very first row.

In the userlisting table there is the following test entries: userid | listingid 1 1 1 2

So one user associated to two listingids. However, it is acting like this userid is only associated with listingid 1, the very first row.

You are only grabbing the first entry.

$a5 = mysql_fetch_array($r5);

This does not fetch the whole query result, but only the first row. If there is none, it will return false.

You have to create a loop to get more results.