Forum Moderators: coopster
<?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
}
?>
And it's a good idea to check with mysql_num_rows() [php.net] to make sure there's actually rows in the result.