Jump to content

[SOLVED] unique id field not showing up(newbie)


dolcezza

Recommended Posts

I can't figure out why my id field isn't showing anything. It is set to auto-increment in the table.

Any help would be appreciated!! I'm new at this!

$id=$_GET['id'];


$query="SELECT * FROM contacts ORDER BY last ASC";
$result=mysql_query($query);
// count how many rows are in the table
$num=mysql_num_rows($result); 
mysql_close();
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th>id</th>
<th>Name</th>
<th>Venue></th>
<th>Phone</th>
<th>Mobile</th>
<th>Fax</th>
<th>E-mail</th>
<th>Website</th>
<th>Address></th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Notes</th>
</tr>
<?php
//loop
if ($num==0) {echo"The database contains no records";}
else
{
$i=0;
while($i<$num){
$id=mysql_result($id,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$venue=mysql_result($result,$i,"venue");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$website=mysql_result($result,$i,"website");
$address=mysql_result($result,$i,"address");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$notes=mysql_result($result,$i,"notes");

?>

<tr>
<td><? echo $id; ?></td>
<td><? echo $last.", ".$first; ?></td>
<td><? echo $venue; ?></td>
<td><? echo $phone; ?></td>
<td><? echo $mobile; ?></td>
<td><? echo $fax; ?></td>
<td><a href="mailto:<? echo $email; ?>">E-mail</a></td>
<td><? echo $website; ?></td>
<td><? echo $address; ?></td>
<td><? echo $city; ?></td>
<td><? echo $state; ?></td>
<td><? echo $zip; ?></td>
<td><? echo $notes; ?></td>
<td><a href='delete.php?id=<?=$id;?>'"'>delete</a></td>
</tr>

Someone will be along to re-write this for you.

 

In the meantime, here's a hint: do ALL of the PHP/MySQL stuff FIRST, then echo out the HTML.

 

Closing the connection to MySQL (mysql_close) is probably killing your resource ($result), which means your records can't be returned at the bottom of the script. Get the records once you have a resource, and then format your HTML.

 

PhREEEk

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.