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 />";
}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.