...

View Full Version : array table



snefmoo
04-17-2009, 07:25 PM
im trying to get an array of information from my database and post each record into a separate table for a guestbook. iv got it working so the data is added to the database but cant seem to get the array working to show the data.
Heres my code for the viewguestbook page:

<?php

$host="localhost";
$username="root";
$password="";
$db_name="mywebsite";
$tbl_name="guestbook";

mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result));
?>

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><div align="left"><strong><span class="style1">View Guestbook | <a href="guestbook.php">Sign Guestbook</a></span> </strong></div></td>
</tr>
</table>
<center> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#c4c2c2">

<tr>
<td width="117"><span class="style1">Name</span></td>
<td width="14">:</td>
<td width="357"><?php echo $rows['name']; ?></td>
</tr>
<tr>
<td><span class="style1">Email</span></td>
<td>:</td>
<td><?php echo $rows['email']; ?></td>
</tr>
<tr>
<td valign="top"><span class="style1">Comment</span></td>
<td valign="top">:</td>
<td><?php echo $rows['comment']; ?></td>
</tr>
<tr>
<td height="25" valign="top"><span class="style1">Date/Time </span></td>
<td valign="top">:</td>
<td><?php echo $rows['datetime']; ?></td>
</tr>
</table>
<br></center></div>


<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>

</tr>
</table>
<BR>
<?php

mysql_close();
?>

any pointers would be really appreciated as it is for my dissertation which is due in soon and this is all i need to complete my work. :)

Fumigator
04-17-2009, 08:19 PM
Check to make sure your query worked.

Hayyel
04-18-2009, 01:58 AM
Confused what the second table is for?!


<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>

</tr>
</table>
<BR>

If you are asking how to take each $row from the query and display it then I would try something like:


while($rows=mysql_fetch_array($result)) {
?>
"Table Code Here"
<?
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum