| | |
while function and "mysql_fetch_assoc() not a valid MySQL result resource"
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 12
Reputation:
Solved Threads: 0
Hi all. I am having a problem I've not encountered before. When using mysql_fetch_assoc() in while(), I am getting the following error:
[PHP]$query = "SELECT * FROM comments WHERE archive_id = '$archive_id'";
$result = mysql_query($query);
while ( $result = mysql_fetch_assoc($result) ) {
$date = $result["date"];
$name = $result["name"];
$comments = $result["comments"];
echo "$date, $name, $comments";
}[/PHP]I have checked database connections, I've run the query through phpMyAdmin, and checked for spelling/syntax errors.
Any ideas? Thanks!
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in archives.php on line 81However, when taking it out of the while(), it works fine. The following is the code snippet...
[PHP]$query = "SELECT * FROM comments WHERE archive_id = '$archive_id'";
$result = mysql_query($query);
while ( $result = mysql_fetch_assoc($result) ) {
$date = $result["date"];
$name = $result["name"];
$comments = $result["comments"];
echo "$date, $name, $comments";
}[/PHP]I have checked database connections, I've run the query through phpMyAdmin, and checked for spelling/syntax errors.
Any ideas? Thanks!
Try this:
[PHP]
$query = "SELECT * FROM comments WHERE archive_id = '$archive_id'";
echo $query;
exit();
$res = mysql_query($query);
while ( $result = mysql_fetch_assoc($res) ) {
$date = $result["date"];
$name = $result["name"];
$comments = $result["comments"];
echo "$date, $name, $comments";
}[/PHP]
[PHP]
$query = "SELECT * FROM comments WHERE archive_id = '$archive_id'";
echo $query;
exit();
$res = mysql_query($query);
while ( $result = mysql_fetch_assoc($res) ) {
$date = $result["date"];
$name = $result["name"];
$comments = $result["comments"];
echo "$date, $name, $comments";
}[/PHP]
![]() |
Similar Threads
- Supplied argument is not a valid MySQL result resource (MySQL)
- Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: question about connecting odbc to sql through php script
- Next Thread: Tidy up output of ping.
Views: 16298 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





