Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.