Forum Moderators: coopster

Message Too Old, No Replies

Unable to query DB correctly.

         

paseo

1:21 am on Feb 2, 2008 (gmt 0)

10+ Year Member



I am trying to pull information from a MySQL Database. I have the code im using below. It looks failry simple however im am unable to extract any data. I have tried 2 other methods as well. No error messages are generated and all that is displayed on the page is the echoed Databse Results. But no results below. There is a while statement that i guess loops the results until complete. Anybody know why this isnt working?

<?php

include ("/db.php");

$sql = mysql_connect("$db_ip","$db_user","$db_pass");
if (! $sql) {
die('Could not connect to server: ' . mysql_error());
}
elseif(! mysql_select_db("$db_name", $sql)){
die('Could not open database: ' . mysql_error());
}

echo "<b><center>Database Output</center></b><br><br>";

$query="select * from table"; // query string stored in a variable
$rt=mysql_query($query); // query executed
echo mysql_error(); // if any error is there that will be printed to the screen

while($nt=mysql_fetch_array($rt)){
echo "$nt[day] $nt[time] $nt[year]<br>"; // name class and mark will be printed with one line break at the end
}

?>

cameraman

5:55 am on Feb 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember the syntax I showed you in your other thread [webmasterworld.com]?
echo "{$nt['day']} {$nt['time']} {$nt['year']}<br>";

And it's a good idea to check with mysql_num_rows() [php.net] to make sure there's actually rows in the result.