first id from db not showing

Posted on 16th Feb 2014 by admin

I have a php script which displays the content of a mysql table as a html table with sorting, delete/update button, etc. the problem is I can't make it show the first value inserted in the db, it only shows from the second id onwards, example:

instead of :

ID Surname Name
1 Test John
2 Test Anna

it shows:

ID Surname Name
2 Test Anna
3 Test Jorge

omitting the first id in the db

"index.php"
Code: <?php
include("connect.php");

$result = mysql_query("SELECT * FROM contact");
$id = mysql_result($result,$i,"id");

echo "<table border='1' class='rowstyle-alternate'>
<tr>
<th> </th>
<th> </th>
<th class='sortable-numeric'>ID</th>
<th class='sortable-text'>Surname</th>
<th class='sortable-text'>Name</th>
<th class='sortable-numeric'>Phone1</th>
<th class='sortable-numeric'>Phone2</th>
<th class='sortable-text'>Location</th>
</tr>";

while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . "<a href="delete.php?id=$id">Delete</a>" . "</td>";
echo "<td>" . "<a href="update.php?id=$id">Update</a>" . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['phone1'] . "</td>";
echo "<td>" . $row['phone2'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close();
?>

"delete.php"

Code: <?php
$id = $_GET['id'];
?>
<html>
<head>
<title>Do you want to delete this?</title>
</head>
<body>
<div align="center">
<h2>Do you want to delete this?</h2>
<h2><a href="deleted.php?id=<?php echo "$id" ?>">Yes</a> - <a href="index.php">No</a></h2>
</div>
</body>
</html>

Other forums