Jump to content


pagination help...


6 replies to this topic

#1 juketsu

    Young Padawan

  • Members
  • Pip
  • 93 posts
  • Location:NC

Posted 28 September 2005 - 02:40 PM

i figured out how to do PHP pagination but I want have the links in a drop down menu instead of links, how would i do that...ive tried everything...

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 September 2005 - 05:44 PM

Probably the same way you would do the links... Only difference being, the use of javascript.
Try this:
<script type="text/javascript">
function go_to(object){
	window.location = object.options[object.selectedIndex].value;
}
</script>
<select name="name" onChange="go_to(this);">
<option value="URL">DISPLAY</option>
</select>


#3 juketsu

    Young Padawan

  • Members
  • Pip
  • 93 posts
  • Location:NC

Posted 28 September 2005 - 06:50 PM

i meant with php pagination...or does that work w/php...

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 September 2005 - 07:06 PM

Well, as long as the user has a javascript enabled browser, that will work with the php. Naturally, you'll have to use php to echo out the different options with the proper info in place of what i had in caps. But you need to know 2 things.
1. PHP is server side, no more. It can only affect what HTML the end-user actually sees.
2. I have no idea how to make a select box into a link, other then what i showed above. I'm sure there are other ways, but that's the only one i know.

#5 juketsu

    Young Padawan

  • Members
  • Pip
  • 93 posts
  • Location:NC

Posted 28 September 2005 - 07:57 PM

ok...thx ne way for ur help...

#6 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 29 September 2005 - 01:05 AM

<?php
$links = array (
	'Google|http://www.google.com/',
	'MSN|http://www.msn.com/',
	'Yahoo!|http://www.yahoo.com/',
);
echo "<select>\n";
for ($i = 0; $i < count($links);) {
	$link = $links[$i];
	list($title, $link) = split('[|]', $link);
	echo "  <option onclick=\"window.location='$link'\">$title</option>\n";
	$i++;
}
echo "</select>";
?>
That should work for you, just change the links, but make sure you leave the | in between the title and url's

Edited by HaloprO, 29 September 2005 - 01:12 AM.


#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 29 September 2005 - 06:00 PM

No offense, but you can do 2 things to make that code better.
1. Use the for loop for in the way it's intended to be used, and add all the attributes to the list:
<?php
$links = array (
'Google|http://www.google.com/',
'MSN|http://www.msn.com/',
'Yahoo!|http://www.yahoo.com/',
);
echo "<select>\n";
for ($i = 0; $i < count($links); $i++) { // Added $i++
$link = $links[$i];
list($title, $link) = split('[|]', $link);
echo "  <option onclick=\"window.location='$link'\">$title</option>\n";
// Moved $i++
}
echo "</select>";
?>
Or 2. Instead of relying on the split (or explode) functions, use a foreach loop and change the array set up to something like this
$links = array ('Google' => 'http://www.google.com/',
'MSN' => 'http://www.msn.com/',
'Yahoo' => 'http://www.yahoo.com/');
Note also the fact that you added a comma after yahoo that shouldn't be there.

p.s. These are just tips, i'm not trying to argue with anybody or make anybody mad, just point some stuff out.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users