Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

previous next links

$
0
0

I have the following code allowing me to navigate to the previous or next record in the db.  In the code below, I would like to swap 'new_date' (which is in the 000-00-00) format for the existing 'record_id' in the script.  I need to navigate via the new_date because it is possible with my program to delete a record and reenter it later for that passed date causing the record_id to be out of sinc with the reord_id.

 

Example:  My record_id is auto-increment so if I find a mistake in a past record and go to fix it for that date in the past, my auto-increment would be 235, 236, 237, 568, 239, 240 etc., so I  can't use record_id to navigate next and previous. 

 

When I use new_date instead of record_id, my error says either that the query was empty, or that Variable id not defined. Script terminating.

 

I would appreciate any help you can give, Thanks!

 

Doug

 

This is also on a web page, so here's my code:

 

php:

 

$current_id = $_GET['record_id'];
$record_id = $current_id;

$prevquery = "SELECT * FROM daily_sales WHERE record_id < $current_id ORDER BY record_id DESC LIMIT 1";

echo $current_id;
$prevresult = mysql_query($prevquery) or die(mysql_error());
while($prevrow = mysql_fetch_array($prevresult))
{
$previd = $prevrow['record_id'];
}

$nextquery = "SELECT * FROM daily_sales WHERE record_id > $current_id ORDER BY record_id ASC  LIMIT 1";
$nextresult = mysql_query($nextquery) or die(mysql_error());
while($nextrow = mysql_fetch_array($nextresult))
{
$nextid  = $nextrow['record_id'];
}

 

 

 

html:

 

<a href="http://www.mywebsite.com/view.php?record_id=<?php echo $previd; ?>">Previous</a>

<a href="http://www.mywebsite.com/view.php?record_id=<?php echo $nextid; ?>">next</a>

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles