Thanks to all you gurus out there.
I am trying to make a previous and next button on a profile page. If I am looking at the profile for Arnsdorf, I want a previous button to link to Antonio and a next button to link to Baldeviso.
IDs aren't sequential as you can see from the output which is ordered by lname:
ID: 22 Name: Airaghi
ID: 36 Name: Antonio
ID: 27 Name: Arnsdorf
ID: 13 Name: Baldeviso
ID: 46 Name: Barnes
Here's my code:
$sql = "SELECT id,lname FROM profiles ORDER BY lname";
$query = mysql_query($sql);
if (!$query) {
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_array($query, MYSQL_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["lname"]);
echo "<br>";
}
mysql_free_result($query);
But I can't get it into an array
to sort it.
I was hoping to create a 3 column multi-dimensional array
with a data set that looks roughly like this:
row,id,lname
1,22,Airaghi
2,36,Antonio
3,27,Arnsdorf
4,13,Baldeviso
5,46,Barnes
I could then figure out how to get the number of the row for say Arnsdorf. Then get the row number for +1 and -1, so that I could get their respective ids for use in my hyperlink.
I have looked for hours and I can't find any code examples that will dump the mysql data into a numbered multi-dimensional array permanent enough to do this sort on. Thanks for your help.