Current location: Hot Scripts Forums » Programming Languages » PHP » page browsing problem


page browsing problem

Reply
  #1 (permalink)  
Old 04-16-04, 11:23 AM
mivec mivec is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy page browsing problem

hi all,
ok i don't know if any of u can help me in this.

scenario:
Quote:
i am trying to build a page where will only display 6 records(images). so u may ask what if it's more than six? yes..this is what i am trying to do. this page only displays 6 images at one time eventhough it is 100images in the DB. so...there will be page numbers like this forum has <<1 2 3 4...>> and each of these can only display 6 images. so if there are 12 images there should only be 2 pages..<<1 2>>. if there are only 6 images then it would be <<1>>. understand what i am trying to say here?. it's sopmething like a page browser where u can go to any number of page u like and it will display the records there.
actually..i have the code here.i have done partially of it but it doesn't raelly work like how it is suppose to be. it can go to the page u want but it won't display it out and when u go to the next page or previous the records just don't display. here is the code

PHP Code:

$sql "SELECT * FROM tblgallery WHERE username = '" $_GET["username"] . "'";
   
$rs mysql_query($sql);
   
$nRows mysql_num_rows($rs);
   
   
/* Set the default records to be shown per page as 5 */
   
$pageSize 3;
   
   
/* Page is not set then set it to page 1 */
   
if(!isset($_GET["page"])) 
    
$page 1;
   else
    
$page $_GET["page"];
   
   
$startPos $page $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
   
$sql .= ' LIMIT ' $startPos ', ' $pageSize//now break into paged sections
   
$rs mysql_query($sql) or die('Error: ' mysql_error());
   
   
    
   echo(
'<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
   echo(
' <tr><td align=right><span class="nav">');
   
   if (
$page != 1) {
    
$prev $page 1;
    echo 
'<span class="nav"><a href="' $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'">&lt;&lt;</a>';
   }
   else
    echo (
"<span class=\"nav\">&lt;&lt;");
   
   
$totalPage $nRows $pageSize;
   for(
$i 1$i <= $totalPage$i++) {
    
/* inactive page, don't add linking */
    
if ($i == $page){ echo '&nbsp;' $i;} 
    
/* page active, add linking */
    
else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>';}
   }
   if ((
$nRows $pageSize) != 0) {
    
/* inactive page number */
    
if ($i == $page){ echo '&nbsp;' $i; }
    
/* active page, linked */
    
else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>'; }
   }
   if( (
$nRows - ($pageSize $page)) > 0) {
    
$next $page 1;
    echo 
'&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $next '">&gt;&gt;</a></span>';
   } 
   else{
    echo 
"&nbsp;&gt;&gt;</span>";
    echo(
"</td>");
        echo(
"</tr>");
      echo(
"</table>");
   
        echo(
'<table width="100%" border="0" cellspacing="1" cellpadding="4">');
     while (
$row mysql_fetch_object($rs)) { 
          echo(
"<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
      <td align=center border=1><img src=\"
$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>");
         }
//close while 
the username comes from this which i have posted before:

PHP Code:

 echo("<tr bgcolor=\"#FEDCED\"> 
          <td width=\"12%\">&nbsp;</td>
          <td width=\"6%\">&nbsp;</td>
          <td width=\"82%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#104071\"><a href=\"photoUpload.php?username="
.$_POST['txtUserID']."&mode=list\">-Upload New Photo</a></font></td> 
    </tr>"
); 
i have already corrected the syntax so..it's correct now. but now the focus is on the page browsing. pls help for the last time.....i am going nuts already.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-17-04, 01:36 AM
the_mole001's Avatar
the_mole001 the_mole001 is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Australia
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Hello mivec,

I think your issue lies where u try to add the LIMIT part to the origional $sql variable. I think you should redeclare what you are looking for so:

$sql .= ' LIMIT ' . $startPos . ', ' . $pageSize;

becomes

$new = "SELECT * FROM tblgallery WHERE username='".$_GET['username']."' LIMIT ".$startPos.", ".$pageSize."";
$results = mysql_query($new) or die('Error: ' . mysql_error());

Hopefully, that will allow you to view the right results on each page.

Peter
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-17-04, 04:14 AM
snipe's Avatar
snipe snipe is offline
New Member
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
-- snipe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-17-04, 04:43 AM
mivec mivec is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
i saw ur page snipe....but it's kinda complicated...dun really understand...could u teach me how to use the page snippet?or what do i need to change to fit my assignment?u see...it's suppose to show 6 records of images and then if it's more than 6 it goes to the other page..and so on.....i think u know what i mean right?pls help..do u have any messenger so that i can contact u?it's urgent......
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
Automatically refresh page after page load failure jdugger JavaScript 3 08-05-10 10:16 AM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
PHP/MySQL PAGE LAST UPDATED script problem digioz PHP 2 01-05-04 10:38 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Problem with page redirection Mailman PHP 6 12-11-03 12:36 PM


All times are GMT -5. The time now is 12:13 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.