Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation System Array

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I am trying to create simple next/back links to navigate through a record set $Result, which will be individual next/previous images). So far it shows all values as simple hyperlinks and the values themselves are just a comma-separated list of IDs. It works but I need only the previous and next and have only the vaguest idea how to go about it. Below is what I have so far, can someone help me flesh it out a little?

Code:
if (mysql_num_rows($Result) > 0) {
  $NewRow = 0;
    while ($row = mysql_fetch_row($Result)) {
      if ($NewRow) {
          $NewRow .= ","."<a href=\"index.php?TypeID=".$row[0]."\">".$row[0]."</a>";
      } else {
           $NewRow = "<a href=\"index.php?TypeID=".$row[0]."\">".$row[0]."</a>";
      }
    }
   echo $NewRow;
}

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Thanks, no I hadn't seen it but I am not sure that it applies as it's not actual pages that I am filtering through. This navigation is supposed to navigate through categories, each of which might have many entries. In other words, when I select NEXT, it goes to the next category and pulls up all entries under it so the record set and looping through it are separate from that which pulls up the actual entries. However, I'll study the FAQ434-5244 tomorrow to see if anything is usable. Thanks again.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
One thing is that the category values are not necessarily in any kind or numeric order although if on a specific category, I know which it is. When I first load the "page" from the menu, it lists all categories for that area. For example, one "page" has available categories of: 65,69,98,97,99,108,96,59

What I don't know is how to get the next or previous one as I know nothing about arrays and what I read confused me more than it helped! Although not technically an array, it seems that using it as one is what I need to do but I don't know how.

Also, if I'm looking at only the first one or last, I want only a next or previous while if I'm looking at one in between others, it needs both next and previous.

I looked through FAQ434-5244 but, because it deals in pages, I do not see anything that will work for what I am trying to do. I would really appreciate any help that someone might be able to give to get this going! Thanks.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
I've almost got it except for some bugs in the areas marked red.

On the first, there is a second parameter that needs to be passed along with some entries but it seems to be on all of them because I am not sure how to incorporate it properly.

On the second, rather than having the proper values of:
65,69,98,97,99,108,96,59

$NewRow now has the values of:
656569,6569,98,6569,98,97,6569,98,97,99,6569,98,97,99,108,6569,98,97,99,108,96,6569,98,97,99,108,96,59,

which, of course, are useless. That is, it actually works to a degree but it never has the first two values available.

Any ideas?

Code:
if (mysql_num_rows($Result) > 0) {
   while ($row = mysql_fetch_row($Result)) {
     [COLOR=red]if ($row[1]) {
       $AddParam = "&CompactList=1";
     } else {
       $AddParam = "";
     }[/color]

     [COLOR=red]if ($NewRow) {
       $NewRow .= $row[0]. ",";
     } else {
       $NewRow .= $row[0];
     }[/color]
			
   }

   $TypeID = $_POST['TypeID'];
   
   if ($TypeID) {
     $TypeNav = explode(",", $NewRow);
     
     for($i = 0; $i < count($TypeNav); $i++){
       if ($TypeNav[$i] == $TypeID) {
         $CurrentType = $i;
       }

       $PrevType = $CurrentType -1;
       $NextType = $CurrentType +1;

       if (array_key_exists($PrevType, $TypeNav) && $PrevType > 0 && $PrevType != $CurrentType) {
         $PrevButton = $TypeNav[$PrevType];
         $PrevButton = "<a href=\"index.php?TypeID=" . $PrevButton . $AddParam . "\"><img src=\"Prev.gif\" border=\"0\"></a>&nbsp;&nbsp;";
       } else {
         $PrevButton = "";
       }

       if (array_key_exists($NextType, $TypeNav)) {
         $NextButton = $TypeNav[$NextType];
         $NextButton = "&nbsp;&nbsp;<a href=\"index.php?TypeID=" . $NextButton . $AddParam . "\"><img src=\"Next.gif\" border=\"0\"></a>";
       } else {
         $NextButton = "";
       }
    }
  }	
	echo $PrevButton . $NextButton;
}

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top