Forum Moderators: coopster
$result = mysql_query("SELECT * FROM table_1 ORDER BY rec_id DESC LIMIT 0, 20");
after this, when I do
print_r($result);
the output is: "Resource id #3"
and later in the code, when I do this:
$row = mysql_fetch_array($result);
I get the following error in my apache error.log file:
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in guestbook.php on line 36
I'm not sure what's wrong, so if you have questions about my php configuration, etc, I'll answer them.
thanks in advance
The query syntax looks good to me. Are you sure the table name exists and is correct (double check for case sensitivity)? How about the column name? You may also want to make sure that your connection is established and you have selected the correct database.
$link = mysql_connect('server_name', 'userid', 'password') or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error());
$database = mysql_select_db('my_database', $link) or exit('Could not select database (' . mysql_errno() . '): ' . mysql_error());
I'm not sure if this is the best way or not, but here is how I code my database pulls in PHP:
$sql = "SELECT * FROM table_1 ORDER BY rec_id DESC LIMIT 0, 20;";
$sql_res = mysql_query($sql); //execute query
//for error checking you can add the following line
print mysql_error();
$row = mysql_fetch_array($sql_res);
I like this way, because if you are passing variables to the sql statement, to see what you passed you just need to echo the $sql variable. Also, by putting the print mysql_error() statment in there, you know right away if you have a problem with the sql (Assuming you have error_reporting() set correctly).
I would try these and see what you come up with.
Conor
[edited by: jatar_k at 5:21 pm (utc) on May 17, 2004]
[edit reason] no sig urls thanks [/edit]