Hello, this problem is probably simple but the code is hard to follow.
Addume i have successfully connected to and selected a mysql dastabase.
My database has a table inside it called "staff". Staff has 4 collums, one called id, one called name, one called, position and one called email. The table has 2 rows, one for a person named ben knowles and one for a person named bob vila. Bob vila is the last entry in the table.
What i want to do is list each person's name, email and position. Below is the code i used.
$now = 1;
$query = "select max(id) from staff";
$result = mysql_query($query);
$last_id = mysql_fetch_array($result) or die (mysql_error());
while ($now != $last_id[0]) {
$query = "SELECT * FROM staff WHERE id=$now";
$result = mysql_query($query);
$member = mysql_fetch_array($result) or die (mysql_error());
echo "$member[1] <p>";
echo "$member[2] <p>";
echo "$member[3] <p>";
$now++;
}
As you can see, $last_id[0] contains the id of the last entry. $member[1], [2] and [3] is the info from the rest of the feilds.
HERE'S THE PROBLEM:
even though there are 2 rows in the table, it only lists the data from the first one. You can see it execute at:
<!-- w --><a class="postlink" href="http://www.x86central.com/staff_help.php">www.x86central.com/staff_help.php</a><!-- w -->
Can anyone help me?
Addume i have successfully connected to and selected a mysql dastabase.
My database has a table inside it called "staff". Staff has 4 collums, one called id, one called name, one called, position and one called email. The table has 2 rows, one for a person named ben knowles and one for a person named bob vila. Bob vila is the last entry in the table.
What i want to do is list each person's name, email and position. Below is the code i used.
$now = 1;
$query = "select max(id) from staff";
$result = mysql_query($query);
$last_id = mysql_fetch_array($result) or die (mysql_error());
while ($now != $last_id[0]) {
$query = "SELECT * FROM staff WHERE id=$now";
$result = mysql_query($query);
$member = mysql_fetch_array($result) or die (mysql_error());
echo "$member[1] <p>";
echo "$member[2] <p>";
echo "$member[3] <p>";
$now++;
}
As you can see, $last_id[0] contains the id of the last entry. $member[1], [2] and [3] is the info from the rest of the feilds.
HERE'S THE PROBLEM:
even though there are 2 rows in the table, it only lists the data from the first one. You can see it execute at:
<!-- w --><a class="postlink" href="http://www.x86central.com/staff_help.php">www.x86central.com/staff_help.php</a><!-- w -->
Can anyone help me?