Iceman512 Posted January 27, 2007 Share Posted January 27, 2007 Hi everybody,I cannot get the following script to retrieve anything from my database. I am getting the traditional error; "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ...". I have been checking the db connection values and db name for the last several hours, eventually I copied them from the database itself, so I'm pretty sure there are no errors there. Any suggestions would be helpful.[code]<?php$dbhost = 'host';$dbuser = 'database_user';$dbpass = 'database_password';$dbname = 'database_name';$con = mysql_connect($dbhost,$dbuser,$dbpass);if (!$con) { exit('Error! Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con);$result = mysql_query("SELECT count(*) FROM table");if ($result <= "1") { echo "The database is currently empty"; } $result = mysql_query("SELECT id, description, cost_inc_vat, sale_inc_vat, model FROM table ORDER BY id DESC");while($row = mysql_fetch_array($result));{?><table cellpadding="0" cellspacing="0" align="center" width="100%"> <tr><th id="css" colspan="2" align="left">Items In Database</th></tr> <tr><td> </td></tr> <tr> <td><font id="css"> <?php echo $row['description']; ?> </font></td> <td><font id="css"> <?php echo $row['cost_inc_vat']; ?> </font></td> <td><font id="css"> <?php echo $row['sale_inc_vat']; ?> </font></td> <td><font id="css"> <?php echo $row['model']; ?> </font></td> </tr></table><?php}mysql_close($con);?>[/code]Thanks! Link to comment https://forums.phpfreaks.com/topic/35949-select-from-db-error/ Share on other sites More sharing options...
micmania1 Posted January 27, 2007 Share Posted January 27, 2007 [code=php:0]<?php$dbhost = 'host';$dbuser = 'database_user';$dbpass = 'database_password';$dbname = 'database_name';$con = mysql_connect($dbhost,$dbuser,$dbpass);if (!$con) { exit('Error! Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con);$result = mysql_query("SELECT count(*) FROM table");if ($result <= "1") { echo "The database is currently empty"; } $result = mysql_query("SELECT id, description, cost_inc_vat, sale_inc_vat, model FROM table ORDER BY id DESC");while($row = mysql_fetch_array($result)){echo '<table cellpadding="0" cellspacing="0" align="center" width="100%"> <tr><th id="css" colspan="2" align="left">Items In Database</th></tr> <tr><td> </td></tr> <tr> <td><font id="css"> '.$row['description']'. </font></td> <td><font id="css"> '. $row['cost_inc_vat'].' </font></td> <td><font id="css"> '.$row['sale_inc_vat'].' </font></td> <td><font id="css"> '.$row['model'].'</font></td> </tr></table>';}mysql_close($con);?>[/code] Link to comment https://forums.phpfreaks.com/topic/35949-select-from-db-error/#findComment-170495 Share on other sites More sharing options...
Iceman512 Posted January 27, 2007 Author Share Posted January 27, 2007 Thanks micmania1,Your code works like a charm. Thanks a bunch!Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/35949-select-from-db-error/#findComment-170496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.