WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-31-2003, 11:54 AM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default limiting results

Hi all:

I have my sitemap organized by product name. Needless to say this gets longer the more products I add to my database. Can some one please tell me how I can limit the results per page? I tried it earlier and got it to display the first page correctly but not the other pages.

Here is the page as it currently stands

http://www.jacksretail.com/online-sh...es-sitemap.php
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #2 (permalink)  
Old 10-31-2003, 03:03 PM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

You can accomplish this by using a limit in the sql statement.

Code:
if(!isset($_GET['page']))
{
  $page = 1;
}
else
{
$page = $_GET['page'];
}
$query = 'select * from products limit '.$page.',10';
then for the next/previous buttons you just add $page+1 and $page-1 to the url of the link.

If you need some more help let me know.
Reply With Quote
  #3 (permalink)  
Old 10-31-2003, 04:08 PM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

Thx:

I'm still having trouble with this part. Did I do something wrong?

start of code:
------------------------------------

<?

if($page != 1){
$pageprev = $page-1;
}

echo("<a href=\"jackscategories.php?$page=$pageprev\">PREV</a> ");

$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo($i." ");
else
echo("<a href=\"jackscategories.php?$page=$i\">$i</a> ");
}

if(($totalrows % $limit) != 0){
if($i == $page)
echo($i." ");
else
echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");
}

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page+ 1;
echo("<a href=\"jackscategories.php?page+1=$pagenext\">NEXT </a>");
}else
echo(" NEXT ".$limit);
mysql_free_result($result);
?>


It's giving me the following error message:

Warning: Division by zero in /home/wwwjack/public_html/online-shopping-at-discount-prices-sitemap.php on line 215
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #4 (permalink)  
Old 10-31-2003, 05:59 PM
httpman's Avatar
WebProWorld Pro
 

Join Date: Aug 2003
Location: France
Posts: 196
httpman RepRank 0
Default

Hello.

Your code is not so clear.
You make a reference to $pageprev in the first block, and the way you use it is OK, but then you put an echo statement - but what happens if $page is not != 1 ?
$pageprev should be initialised to $page - I guess you did it, but you forgot to tell it in this post.


Note : the fictitious 'www' links above will show a link, but they don't go anywhere !.. Just type 'www.' in this post and you will display a link. I just put those words as an example, there is no target to "www.blabla" as you can easily imagine !!!

What makes me answering this post is your PREV / NEXT links at the bottom of your web page. It show this information :
* prev : www.blabla.php?1-1=
* next : www.blabla.php?1+1=

What are those ?1-1=' and '?1+1=' parameters ? This is not the good way to send 'post' parameters. You should use that way :

* prev : www.blabla.php?page=z
* next : www.blabla.php?page=z

Where z is the page number you want to go to. Then in the target page, you can easily catch the "$page" value (as your parameter is called "?page=") via that line :

foreach($HTTP_POST_VARS as $name=>$value) $$name=$value;

If you need more parameters, you can use that way :

www.blabla.php?param1=xxx&param2=yyy&param3=zzz

Then after using the "foreach" line above, you get a $param1, $param2 and $param3 set of variables.

Then, back to your issue : using that way to send & catch parameters, you can easily use a "$page" wich is very to use in any SQL limit script.

JP
__________________
www.net-createurs.com [ french only website sorry ! ]
Reply With Quote
  #5 (permalink)  
Old 10-31-2003, 07:55 PM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

ok I see what you say I did. After that you completely lost me. It should be possible to somehow do it with my code, no? Your way is very confusing to me LOL
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #6 (permalink)  
Old 11-01-2003, 04:20 AM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

Code:
<?
$limit=20;
if($page != 1){  
        $pageprev = $page-1; 
}

echo("<a href=\"jackscategories.php?page=$pageprev\">PREV</a> "); //removed $ in front of page

$numofpages = $totalrows / $limit;  
for($i = 1; $i <= $numofpages; $i++){ 
if($i == $page) 
            echo($i." ");  
        else 
            echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");  //removed $ in front of page
}

if(($totalrows % $limit) != 0){ 
if($i == $page) 
            echo($i." "); 
        else 
            echo("<a href=\"jackscategories.php?page=$i\">$i</a> ");
}

if(($totalrows - ($limit * $page)) > 0){ 
$pagenext    = $page+ 1; 
echo("<a href=\"jackscategories.php?page=$pagenext\">NEXT</a>");  //removed +1 after page
}else 
        echo("  NEXT ".$limit);  
mysql_free_result($result); 
    ?>
It would only give you a division by zero error if the $limit variable is not defined. also there is a little problems with the code that i fixed. read the comments.
Reply With Quote
  #7 (permalink)  
Old 11-01-2003, 06:10 AM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

Thx Red:

I almost have it. The only thing wrong now is it's not hyperlinking the Next. Almsot like the pages don't exist?

http://www.jacksretail.com/online-sh...s-sitemap.phps

Is something wrong somewhere else in my script?
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #8 (permalink)  
Old 11-02-2003, 07:02 AM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

You are not assigning $totalrows a value.

After the $result = mysql_query($query) set the totalrows.

$totalrows = mysql_num_rows($result)
Reply With Quote
  #9 (permalink)  
Old 11-02-2003, 11:39 AM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

I must be slow because I did that and am still not getting the next to hyperlink
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #10 (permalink)  
Old 11-02-2003, 11:53 AM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

Update:

I fanlly got the pages to display as links. Unfortunately it's showing the whole query on the other pages. That is it's not limiting the other pages and the layout looks totally different
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
  #11 (permalink)  
Old 11-02-2003, 12:24 PM
WebProWorld Veteran
 

Join Date: Sep 2003
Location: SD
Posts: 771
jackson992 RepRank 0
Default

Woohoo I got it!

Don't ask what I was doing wrong because it goes under bonehead of the month awards
__________________
Jack Mitchell
Home Shopping Online | Sports To Go | Shopping To Go
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0