You are here: Return next/previous record from array with non-consecutive record id's « All PHP « IT news, forums, messages
Return next/previous record from array with non-consecutive record id's

Posted by ClickToWalk on 10/02/41 11:53

I have created some next & previous navigation links on a form I am using to
administer a particular database I am working with.

The navigation links are just hyper links where, on each click, the value of
id is either incremented or decremented. The id is then taken from the url
using
$_GET['id'] to create/ammend the variable $id which is then passed to an
included file to retreive all table records relating to that id.

This all worked fine while record id's in the table were consecutive, but
I've since deleted some records and now in some cases empty records are
returned.

I've been over and over the manual but have been unable to find a solution,
have tried taking other snippets of code which appear to be similar to what
I am trying to achieve but with no success. I guess I'm missing something
pretty fundamental here.

This is a bit of code that I have used to successfully echo all the
available records - with gaps where records are missing - but what
modifications do I need to make to it so that only one row is returned from
the recordset, determined by $id.


$query=sprintf("SELECT locl_id FROM tbl_locl");

$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $result;
die($message);
}


while ($row = mysql_fetch_array($result))
{
echo $row['locl_id']."<br>";
}


Thanks in advance
Matt


"I'm an idealist. I don't know where I'm going, but I'm on my way." - Carl
Sandburg http://clicktowalk.com Page design © Matthew McCabe -
http://mattmadethis.com Site hosted by Xeriom Networks -
http://xeriom.net/in/1019

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация