Page 1 of 1
getting variables...
Posted: Mon Mar 12, 2007 4:49 pm
by kentopolis
I am trying to get this script to work. It will skip to the next page, but it will only go to the next page using the file name, which happens to be puppy_listing.php, it will not include the variable is if they exist, I don't know what I'm doing wrong. Here is where I am using the script (an examle with a variable)
http://www.lovealotkennels.com/puppy_li ... it322=Sort Any help would be greatly appreciated!! Thanks... Oh yeah, I also have only implemented this script on that page for the top "Skip to Page" not the one at the bottom...
Code: Select all
Skip to Page
<?
for($i = 1; $i <= $num_pages; $i++){
if($i == $page){
?>
<? echo $i; ?>
<?
}else{
?>
<a href="<? "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?>?&page=<? echo $i; ?>"><? echo $i; ?></a>
<?
}
}
?>
Posted: Mon Mar 12, 2007 4:56 pm
by RobertGonzalez
Just say no to spaghetti code...
Code: Select all
<?php
for($i = 1; $i <= $num_pages; $i++)
{
if($i == $page)
{
echo $i;
}
else
{
echo '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?&page=' . $i . '">' . $i . '</a>';
}
}
?>
Posted: Mon Mar 12, 2007 5:07 pm
by kentopolis
that worked great, the only thing is, now it's building on itself, is there any way around this? Here is an example of what I mean:
http://www.lovealotkennels.com/puppy_li ... =2?&page=1
it just continues to build pages, it seems to be working, but I just wonder if there is a clean way of doing this.
Sorry for the "Spaghetti" Code, a guy developed this for me and I am modifing it. I'm pretty new to php. Thanks so much for the help, this is invaluable!
Posted: Mon Mar 12, 2007 5:12 pm
by RobertGonzalez
That is because you are keeping the query string when you use $_SERVER['REQUEST_URI']. You might want to try replacing it with basename($_SERVER['SCRIPT_FILENAME']) or something like that.
Posted: Mon Mar 12, 2007 5:30 pm
by kentopolis
when I tried that it stripped out the query... Which I need to still have in there, is there a way to have it trim out the old page #?
Posted: Mon Mar 12, 2007 5:31 pm
by RobertGonzalez
Explain, in plain simple English, what you are trying to accomplish.
Keep in mind also, that the querystring var page is in the $_GET['page'] superglobal on the first run. You can do all sorts of stuff with it...

Posted: Mon Mar 12, 2007 5:41 pm
by kentopolis
plain simple english, hopefully...
I have created the ability to sort the data from mysql and display it on the page,
http://www.lovealotkennels.com/puppy_listing.php, it displays the data dynamically. It creates a variable like "q=Yorkshire&Submit322=Sort", I found that after I created the sorting capability that my pages no longer linked properly because it was creating dynamically generated pages. So, I wanted to add the new page number to the end of the previous variable in order to keep the sorted data but move on to page 2 or 3 of that data. I would like it if the variable stream did not continue to get longer exponentially as page numbers are added to it, which it currently is. I would like to remove the last page number that was sent (if there was one) and add the new one to the end of the variable. I hope that makes sense. I ought to have my wife type this cause I'm usually as confusing as can be, at least she says

. Thanks for any help...
Posted: Mon Mar 12, 2007 5:50 pm
by RobertGonzalez
kentopolis wrote:I would like to remove the last page number that was sent (if there was one) and add the new one to the end of the variable.
Code: Select all
<?php
$page = null;
// I would like to remove the last page number that was sent (if there was one)
if (isset($_GET['page']))
{
// and add the new one to the end of the variable
$page += 1;
}
if (is_null($page))
{
// there was not page query string data
// You should handle this
echo $page; // Or append it, or whatever. Play with this and see what you can do with it
}
?>