Re: Subject: mysql_fetch_array problem
| From: | neil smith | Date: | Sat, 09 Nov 2002 15:59:34 +0000 |
| Subject: | Re: Subject: mysql_fetch_array problem | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-16833@lists.php.net to get a copy of this message | ||
At 14:10 09/11/2002 +0000, you wrote:
Message-ID: <000201c28788$00d50e20$0200a8c0@ncus> From: "Zeus" <zeus_dreamer@myrealbox.com> Subject: mysql_fetch_array problem I try to display mysql database using fetch_array but there seem to problem, i m new with PHP and mysql.I didn't quite sure, what's worng with my codes.i havent include the formyet. the error messages: Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\zeus\shoutbox.php on line 17I think the problem lies in the line below : $result = mysql_query("SELECT * FROM shoutbox BY ID desc LIMIT 5"); shoud read ORDER BY : $result = mysql_query("SELECT * FROM shoutbox ORDER BY ID desc LIMIT 5");
=========If the SQL is not correctly formed, you will not get a result set - hence your error (not a valid MySQL result means no results were returned) To check for returned results, use the function like this : if (mysql_num_rows($result)==0) { print ("No results returned - please check query"); } else { .. rest of your code - while loop etc. } You can always chec a query by printing it, then cut & paste into mysql console or (better imho) insert it into the query box in phpmyadmin - you will get more useful / less cryptic information there. Hope that helps, Regards, Neil Smith.