Jump to content

mysql_fetch_array(): supplied argument is not a valid


advancedfuture

Recommended Posts

I am trying to print a list of output from mySQL using a nested while/for loop. But it keeps generating an error. Suggestions? Thanks!

 

"mysql_fetch_array(): supplied argument is not a valid MySQL result resource"

 

<?php

include 'session.php';
include 'dbconnect.php';

$query = "SELECT * FROM mail WHERE rcpt = '$username'";
$results = mysql_query($query);
$num = mysql_num_rows($results);

while($row=mysql_fetch_array($num))
{
for($i = 0; $i < $num; $i++)
{
	echo $row[$i];
	echo "<br />";
}
}
?>

This still isn't going to do what you're after. Your code doesn't make sense.

 

mysql_num_rows() returns the number of records that you've selected from the database. It doesn't make sense to use this as a constraint within a loop that's looping through a record at a time.

 

If you tell us what you're trying to achieve, we might be able to tell you the best way to go about it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.