Page 1 of 1

Query Values From Array

Posted: Thu Mar 31, 2011 10:16 pm
by jitsking
I'm a bit of a newb to PHP and MySQL. I seem to be having an issue with something. How do I loop through an array, querying each value in the array until the query meets a certain condition.. In this case it would be that the number of rows returned from the query is less than five. Here is what I have:

$query1="SELECT UserID FROM Users where RefID='$userid'";
$result1=mysql_query($query1);
while ($row = mysql_fetch_array($result1, MYSQL_NUM) && $sql2querynum < '5')
{
echo ($row[0]);
echo "<br />";
$sql2 = "SELECT * FROM Users WHERE RefID=$row[0]";
$sql2result = mysql_query($sql2);
$sql2querynum = mysql_numrows($sql2result);
}
Problem is, for every value it echoes out, I get the following warning:
mysql_numrows(): supplied argument is not a valid MySQL result resource

I'm wondering what it I am doing wrong or how to correct this.

Re: Query Values From Array

Posted: Fri Apr 01, 2011 9:48 am
by social_experiment
You could add LIMIT 4 to your query? That way only 4 rows is selected from the database. ;) Next time post in the appropriate section (PHP Code) and use the php code button to encase your php code, it increases your chances exponentially of getting helped.