Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] New page


[SOLVED] New page

Reply
  #1 (permalink)  
Old 08-11-08, 02:56 PM
tolga tolga is offline
Newbie Coder
 
Join Date: Apr 2008
Location: /usr/bin/istanbul
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes [SOLVED] New page

Hello,

I am pulling data from a MySQL database and displaying them on a page. I am breaking it in pages. I have this code where Sonraki (Next) link should give me next page but instead it just adds another &sayfano=1 the URL. Can you help me in this? Regards,

PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel=stylesheet href="css/deri.css">
</head>
<div id="ana"></div>
<div id="logo"><img src="images/logo.gif" style="margin-top: -10px"></div>
<div id="kelebek"><img src="images/kelebek.jpg"></div>
<div class="dugme"><a href="modeller.html"><img src="images/modeller.gif"></a></div>
<div class="dugme"><a href="sorumvar.html"><img src="images/sorumvar.gif"></a></div>
<div class="dugme"><a href="iletisim.html"><img src="images/iletisim.gif"></a></div>
<div class="dugme"><a href="hakkimizda.html"><img src="images/hakkimizda.gif"></a></div>
<div style="float: left; margin-,top: 100px; margin-left: 10px"><img src="images/kelebek1.gif"></div>
<?php
$hedef 
"foto/";
include 
'baglan.php';
$durum $_GET['durum'];
$kategori $_GET['kategori'];
if (!(isset(
$sayfano))) { $sayfano 1; }
$query mysql_query("select id,kod,kucukfoto,fiyat,tanim from satilacak where durum='$durum' and kategori='$kategori' order by kod") or die(die);
$rows mysql_num_rows($query);
$pagerows 12;
$last ceil($rows/$pagerows);
if (
$sayfano 1) { $sayfano 1; } elseif ($sayfano $last) { $sayfano $last; }
$max 'limit ' .($sayfano 1) * $pagerows .',' .$pagerows;
$query_p mysql_query("select id,kod,kucukfoto,fiyat,tanim from satilacak where durum = '$durum' and kategori = '$kategori' order by kod $max") or die(mysql_error());
echo 
"<div style=\"float: left\">";
echo 
"<table align=\"left\">"
echo 
"<tr>";
$i 0;
while (
$row mysql_fetch_array($query_p)) {
$i++;
$id $row['id'];
$kod $row['kod'];
$kucukfoto $row['kucukfoto'];
$tanim $row['tanim'];
$fiyat $row['fiyat'];
echo 
"<td style=\"height=100px\"><a href=\"buyukgor.php?id=$id\"><img src=\"$hedef$kucukfoto\" width=\"130\" height=\"110\"></a><div 
align=center>
$kod</td>";
if(
$i == 4){
    echo 
"</tr>";
    
$i 0;
}
}
echo 
"</table>";
echo 
"</div>";
echo 
"<div>Sayfa: $sayfano / $last</div>";
if (
$sayfano 1) {} else { echo "<a href=\""$_SERVER['PHP_SELF'] . "?" $_SERVER['QUERY_STRING']. "&sayfano=1>İlk</a>";
echo 
"";
$prev $sayfano 1;
echo 
"<a href=\""$_SERVER['PHP_SELF'] . "?" $_SERVER['QUERY_STRING']. "&sayfano=$prev\">Önceki</a>";
}    
echo 
" ---- ";
if (
$sayfano == $last) {}
else {
$next $pagenum 1;
echo 
"<a href=\""$_SERVER['PHP_SELF'] . "?" $_SERVER['QUERY_STRING']. "&sayfano=$next\">Sonraki</a> ";
echo 
" ";
echo 
"<a href=\""$_SERVER['PHP_SELF'] . "?" $_SERVER['QUERY_STRING']. "&sayfano=$last\">Son</a> ";
}
mysql_close($conn);
?>
</html>
__________________
Linux user #388977
Reply With Quote
  #2 (permalink)  
Old 08-12-08, 12:34 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
not sure, but your using
$prev = $sayfano - 1;
but you use
$next = $pagenum + 1;

Didnt see a $pagenum in there, but then again it was just a quick scroll trough.


ah yeah, the reason why your url looks similar to this
www.example.com?sayfano=1&
sayfano=1&sayfano=1&sayfano=1&sayfano=1
is that your including $_SERVER['QUERY_STRING'] in the link without checking if sayfano is already a part of the query string
Reply With Quote
  #3 (permalink)  
Old 08-12-08, 12:56 AM
tolga tolga is offline
Newbie Coder
 
Join Date: Apr 2008
Location: /usr/bin/istanbul
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by <?Wille?> View Post
not sure, but your using
$prev = $sayfano - 1;
but you use
$next = $pagenum + 1;

Didnt see a $pagenum in there, but then again it was just a quick scroll trough.


Ah, didn't realize that. Corrected it. This time the link is http://mtozses/deriaksesuarlar/var.p...kler&sayfano=2 but it never goes to page 2 and it continues adding &page=2 as I keep clicking that link.

Quote:
Originally Posted by <?Wille?> View Post
ah yeah, the reason why your url looks similar to this
www.example.com?sayfano=1&sayfano=1&sayfano=1&sayfano=1&sayfano=1
is that your including $_SERVER['QUERY_STRING'] in the link without checking if sayfano is already a part of the query string
How do I check that?

Regards,
__________________
Linux user #388977
Reply With Quote
  #4 (permalink)  
Old 08-12-08, 02:07 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
it doesnt go to page 2 because your not using the _GET variable. instead your setting the current page to 1 here
[color=#000000]if (!(isset($sayfano))) { $sayfano = 1; }
$sayfano wont be set at this point since your not declaring it.
insert $sayfano = $_GET['sayfano']; before the if.

Quote:
Originally Posted by tolga
How do I check that?


you can remove it completely with something similar to (untested)
PHP Code:

$query_string preg_replace('~(?:&?sayfano=\d+)~'''$_SERVER['QUERY_STRING']); 

and use $query_string for the rest of the script


e:
Also you are using _GET variables in the query as such which is not good. Take a look at this thread and the links in it

Last edited by <?Wille?>; 08-12-08 at 02:12 AM.
Reply With Quote
  #5 (permalink)  
Old 08-12-08, 02:19 AM
tolga tolga is offline
Newbie Coder
 
Join Date: Apr 2008
Location: /usr/bin/istanbul
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes

I did what you said, however now it goes to page 2 only. And I can't see the links for first page and previous pages.
__________________
Linux user #388977
Reply With Quote
  #6 (permalink)  
Old 08-12-08, 02:32 PM
leeprice2006 leeprice2006 is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
I have just written a script to do what you want...

http://www.uposoft.co.uk/tutorials/pagination.php

hope that helps in someway
Reply With Quote
  #7 (permalink)  
Old 08-12-08, 03:42 PM
ianbrind ianbrind is offline
Wannabe Coder
 
Join Date: Jul 2008
Location: Somerset UK!
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by leeprice2006 View Post
I have just written a script to do what you want...

http://www.uposoft.co.uk/tutorials/pagination.php

hope that helps in someway
Sorry it's off topic but, excelent tutorial.
Reply With Quote
  #8 (permalink)  
Old 08-12-08, 03:50 PM
leeprice2006 leeprice2006 is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
ok just thought it would help
Reply With Quote
  #9 (permalink)  
Old 08-13-08, 01:33 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
you cant see the previous page links because the condition for these to show is that your on he last page.
if ($sayfano == $last) {}
else {
$next = $pagenum + 1;


Abolut the tutorial:
its good overall, however there are a few problems with the tutorial.
firstly,
$totalpages
= round($total / $perpage);
if you have 54 users in the database, 10 per page, you get 5.4 pages, which will round to 5. you will never be able to see the last 4 users because your using round and not ceil().

Another thing that i noticed was that you use the same query for counting and selecting but you still execute it twice, which is a waste. num_rows is probably the best way on innoDB based mysql tables but "SELECT COUNT(*)" is significantly faster on MyISAM based tables, which i belive is the default one.
Reply With Quote
  #10 (permalink)  
Old 08-13-08, 07:32 AM
tolga tolga is offline
Newbie Coder
 
Join Date: Apr 2008
Location: /usr/bin/istanbul
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by <?Wille?> View Post
you cant see the previous page links because the condition for these to show is that your on he last page.
if ($sayfano == $last) {}
else {
$next = $pagenum + 1;
I never said I couldn't see the previous page links, but you are right I can't. What I said was Sonraki (Next) link goes to page 2 only.

Regards,

PS: And thanks goes to leeprice2006
__________________
Linux user #388977
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[turnkey] Lyrics site - $149 (LEGAL) rightinpoint General Advertisements 0 10-22-06 04:33 AM
Page reload (Another is this possible) chrisrobertson HTML/XHTML/XML 0 07-31-06 07:30 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.