Forum Moderators: coopster

Message Too Old, No Replies

how to print the output of php mysql in table?

         

shams

1:47 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



hi,
this is what i get from a site to print the mysql query in the table but i get just blank page:

<?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';
?>

brevetoxin

3:35 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



My guess is that there is an error occuring and your server is set up so as not to report errors to the screen. Do you have access to your server error logs?

wsmeyer

6:34 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



his line:

$query = "SELECT id,Code FROM table pharmacy";

Should be:

$query = "SELECT id,Code FROM pharmacy";

William.

eelixduppy

9:35 pm on Nov 29, 2006 (gmt 0)



change:

$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 :)

shams

12:23 am on Nov 30, 2006 (gmt 0)

10+ Year Member



thanks for reply, i change the code according to posts but still i get the blank page without any errors:
<?php
// Make a MySQL Connection
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';
$query = "SELECT id,Code FROM pharmacy";

$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)

jatar_k

12:49 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you may have to take a look at your php.ini and see what the setting of display_errors is, it may be set to off

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?

PatrickH06

7:40 pm on Nov 30, 2006 (gmt 0)

10+ Year Member



Try getting the number of ROWS returned:
$result = mysql_query($query) or die(mysql_error());
echo mysql_num_rows($result);

Should show 3

msalimpk

2:59 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



try this
<?php
// Make a MySQL Connection
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';
$query = "SELECT id,Code FROM pharmacy";

$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';
?>