...

View Full Version : why isn't this database list page not working?



nielsonp
05-21-2008, 08:01 AM
hi, got a problem here....

i am trying to list contents of a database and the page isn't working, nothing is listing in the table, there is data in the the database. here is the code:

cdlist.php

<?php
//following code taken from: http://dalibor.dvorski.net/downloads/docs/InstallingConfiguringDevelopingWithXAMPP.pdf
// Connect and select a database
mysql_connect("localhost", "root", "");
mysql_select_db("cdcat");

//run a query
$result = mysql_query("SELECT * FROM cdcat");
?>

<html>

<head>
<title>CD Catalogue full listing:</title>
</head>

<body>
<h1>CD Catalogue full listing:</h1>

<table border="1" cellpadding="2" cellspacing="3" summary="table holds cd catalogue database">
<tr>
<th>ID</th>
<th>CD Title</th>
<th>Artist</th>
<th>Genre</th>
</tr>

<?php

//loop through all table rows while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>". $row['Id'] . "</td>";
echo "<td>". $row['Title'] . "</td>";
echo "<td>". $row['Artist']. "</td>";
echo "<td>". $row['Genre']. "</td>";
echo "<tr>";
}

//free result memory and close database connection
mysql_free_result($result);
mysql_close();
?>
</table>
</body>

</html>

Len Whistler
05-21-2008, 08:06 AM
Try changing:

//loop through all table rows while ($row = mysql_fetch_array($result))
{

To:

//loop through all table rows
while ($row = mysql_fetch_array($result)) {

nielsonp
05-21-2008, 08:10 AM
cheers Len.
thanks for rapid response! it worked!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum