Forum Moderators: coopster
<?php
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';
$query = "SELECT id,Code FROM table pharmacy";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
echo "<table border='1'>";
echo "<tr><th>Id</th><th>Code</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['Code'];
echo "</td></tr>";
}
echo "</table>";
include 'library/closedb.php';
?>
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
To:
$result = mysql_query($query) or die(mysql_error()); //gives you any mysql errors :)
$result = mysql_query($query) or die(mysql_error());
echo "<table border='1'>";
echo "<tr><th>id</th><th>Code</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['Code'];
echo "</td></tr>";
}
echo "</table>";
}
include 'library/closedb.php';
?>
this is the ouput from mysql prompt:
mysql> SELECT id,Code FROM pharmacy;
+----+------+
¦ id ¦ Code ¦
+----+------+
¦ 1 ¦ 23uy ¦
¦ 2 ¦ gz78 ¦
¦ 3 ¦ 3as ¦
+----+------+
3 rows in set (0.02 sec)
you could also upload a phpinfo [php.net] page and see as well.
what do you see when you view source on the page that shows nothing?
$result = mysql_query($query) or die(mysql_error());
echo "<table border='1'>";
echo "<tr><th>id</th><th>Code</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['Code'];
echo "</td></tr>";
}
echo "</table>";
//}
include 'library/closedb.php';
?>