Link to home
Start Free TrialLog in
Avatar of Adam
AdamFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Navigation bar, navigating between rows in a database (details view) - amending some Tom Muck standard code.

Hello Experts.

I have added a dreamweaver extension to my page (Detail Page Navigation from Tom Muck.com) to allow me to naviagte between detail pages of a Mysql table.

Tom helped me implement the nav bar some while ago and it works fine, however only does so when the order of the database has not been manipulated in any way.

By this, I mean, it displays the first record in the database as the newest entry - defined by the highest 'autonumber' value.  However, this isn't really how I order my database, as I like to be able to order it (through the myphp admin interface) and have records with certain values positioned higher than others.

The Tom Muck code is below, and I guess the problem is that the code is saying treat the MAX autonumber (I take that to be the highest value autonumber in the database) as the record which Tom assumes sits at the top of the database. This isn't the case, and so I'm not sure if I can easily amended to suit my need or not.

What I want to do is navigate between the records in the recordset based on their actual position in the table and NOT based on their autonumber value.

I'm not sure if that makes much sense, but to see what I mean, go to:

http://www.orangutanjapan.com/newsearch/expertssetup17.php?language=&prefecture=&Submit=%92T%82%B7

You will see the order of profiles as they are listed in the database currently. Clicking on the photo takes you to the details page from where you see the nav bar at the top. When you click on the nav bar you see it doesn't take you to the 'Next profile' as per the previous page (and in the database) but to the profile with the next autonumber.

Any help greatly appreciated.

thanks!





//tom-muck.com Set up the detail page navigation suite
$tfm_d_autonumber = 0;
if (isset($_GET["recordID"])) {
  $tfm_d_autonumber = (get_magic_quotes_gpc()) ? $_GET["recordID"] : addslashes($_GET["recordID"]);
}

//tom-muck.com find the previous and first record numbers  
$tfm_prev_link_d = "";
$tfm_first_link_d = "";
$tfm_d_query = "SELECT MIN(autonumber) as autonumber, MAX(autonumber) as PrevRecord 
FROM TestTable WHERE autonumber < $tfm_d_autonumber";
$tfm_d = mysql_query($tfm_d_query, $a) or die(mysql_error());
if($tfm_row_d = mysql_fetch_assoc($tfm_d)) {
  $tfm_prev_link_d = $tfm_row_d["PrevRecord"];
  $tfm_first_link_d = $tfm_row_d["autonumber"];
}

//tom-muck.com find the next and last record numbers
$tfm_next_link_d = "";
$tfm_last_link_d = "";
$tfm_d_query = "SELECT MIN(autonumber) as autonumber, MAX(autonumber) as LastRecord
FROM TestTable WHERE autonumber > $tfm_d_autonumber";
$tfm_d = mysql_query($tfm_d_query, $a) or die(mysql_error());
if($tfm_row_d = mysql_fetch_assoc($tfm_d)) {
	$tfm_next_link_d = $tfm_row_d["autonumber"];
	$tfm_last_link_d = $tfm_row_d["LastRecord"];
}

//tom-muck.com close and destroy the recordset 
mysql_free_result($tfm_d);
 ?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adam

ASKER

Hi jason1178

Thanks for your thoughts on that one. I'll get some of the other issues sorted out with this project of mine and then, as you say, re-evaluate my approach - looking at ORDER BY clause to suit my needs. I shall then post back here - so will leave the post open for the meantime.

Cheers.
Avatar of Adam

ASKER

Yep, fair enough. Thanks guys.

ayounis
Thanks ayounis,

I'm sorry about your other question (AJAX form posting).  I must have totally dropped the ball on that one.