Forum Moderators: coopster
eg (this isnt the code this is to get the idea of what i use the varibles on)
$next = $id+1;
$prev = $id-1;
$prevquery="SELECT record FROM table WHERE id = $prev";
Index ¦ $next ¦ $prev
the thing is when a record is DELETED and lets say $prev doesnt exist this obviously causes a problem.
is there a easy way of getting the next "available" record from mysql in php?
<mysql query here>
$PrevCheck = mysql_num_rows($prevname);
while($PrevCheck == 0)
{
if ($fail < 10)
{
$prev--;
$prevquery="SELECT Record FROM Table WHERE id = $prev";
$prevname = mysql_query($prevquery);
$PrevCheck = mysql_num_rows($prevname);
$fail++;
}
else
{
$PrevCheck++;
$prevresult = "No Previous";
$prevexist=No;
}
}
$sql = "SELECT Record FROM Table where id >= $id order by Record";
# (You may want to throw in a "limit 2" at the end if that's your style)
# The second row is always the one you want (except if you're at last rec already)
And of course
$sql = "SELECT Record FROM Tablle where id <= $id order by Record DESC";'
# Again, the 2nd row has the goods
You can also extend this to sort your records as desired.
i used the SELECT record, id FROM table WHERE id < $id ORDER BY id DESC limit 1
I am still not familar with mysql querying and optimising php code .. im getting there though . You guys are always a good help :)