SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination-Paging links not being displayed

    PHP Code:
        $cid = (int)stripslashes(trim($_GET['cid']));
            
    // category id form the pagination back
            
    $backpage = (int)stripslashes(trim($_GET['back']));
            
    // get page number
            
    if(!isset($_GET['page']))
            {
                 
    $page 1;
            } 
            else 
            {
                
    $page $_GET['page'];
            }
            
    // Define the number of results per page
            
    $max_results 3;        
            
    // Figure out the limit for the query based
            // on the current page number.
            
    $from = (($page $max_results) - $max_results);  
            
    $imagethumbnail=$_POST['imagethumbnail']; 
            if(
    $cid
                { 
                
    $imagethumbnail=$_POST['imagethumbnail']; 
                include(
    "dbconnect.php"); 
                
    $gQuery="SELECT * FROM gallery WHERE cid='$cid'"
                
    $rs=$con->query($gQuery); 
                if(!
    $rs
                { 
                    
    $dbError="Error:Failed to executing query".mysqli_error($con); 
                } 
                else 
                { 
                    
    $count=$rs->num_rows
                    if(
    $count>0
                    { 
                        
    print_r($data); 
                        
    $data=$rs->fetch_assoc(); 
                        
    $imagethumbnail=$data['imagethumbnail']; 
                    } 
                    else 
                    { 
                        
    print_r($data); 
                        echo 
    "<br/>Project Cannot be Found"
                    } 
                } 
            }  
                        
    $query "SELECT count(*) FROM gallery"
                        
    $rs=mysqli_query($con,$query); 
                        if(!
    $rs
                        { 
                            echo 
    "Error:".mysqli_error($con); 
                        } 
                        else 
                        { 
                            
    $query_data=mysqli_fetch_row($result); 
                            
    $numrows $query_data[0]; 
                            
    $rQuery="SELECT imagethumbnail FROM gallery where cid='$cid' ORDER BY id DESC LIMIT $from$max_results";
                            
    $rs=mysqli_query($con,$rQuery); 
                            if(!
    $rs
                            { 
                                echo 
    "Error:".mysqli_error($con); 
                            } 
                            else 
                            { 
                                if(
    $count>0
                                { 
                                    
    $query_data mysqli_fetch_row($rs); 
                                    
    $num_rows $query_data[0]; 
                                    while(
    $data=$rs->fetch_assoc()) 
                                    { 
                                        echo 
    "<tr><td><img src=gallery/".$data['imagethumbnail']." width=\"100px\" height=\"100px\"></td><td>".$data['description']."</td></tr><br/>"
                                    } 
                                }      
                            } 
                        }
                        echo 
    "<div>
                                <p align='left'>"
    ;
                                    
    // Figure out the total number of results in DB:
                                
    $cQuery="SELECT * ".
                                        
    "FROM gallery where cid='$cid'";

                                
    $rs=mysqli_query($con,$cQuery);
                                if(!
    $rs)
                                {
                                    echo 
    "Error:".mysqli_error($con);
                                }
                                
    $total_results=mysqli_num_rows($rs);
                                
    // Figure out the total number of pages. Always round up using ceil()
                                
    $total_pages ceil($total_results $max_results);

                                if (
    $total_pages 0)
                                {  
    // build links if more than one page

                                    // Build Page Number Hyperlinks
                                    
    $result_final .=  "page: ".$page.' of '.$total_pages."";
                                    
                                    
    // Build first page link
                                    
    if(($page) > $max_results)
                                    {
                                        
    // check if the page sent
                                        // does it equal the amount of total_pages?
                                        
    if($page == $total_pages)
                                        {
                                            
    $start = ($page $max_resultsl);
                                            
    $end = ($page 1);
                                            
    $result_final .=  "<a href=".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=1\" title='First Page'>&laquo; first</a>";
                                        } else { 
                                            
    $start = ($page $max_resultsl);
                                            
    $end = ($page 1);
                                            
    $result_final .=  "<a href=".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=1\" title='First Page'>&laquo; first</a>";
                                        }
                                    } else {
                                        if(
    $total_pages $max_results){
                                            
    $start 1;
                                            
    $end $total_pages;                                        
                                        } else {
                                            
    $start 1;
                                            
    $end $max_results;
                                        }
                                    }
                                                                
                                    
    // Build Previous Link
                                    
    if($page 1){
                                        
    $prev = ($page 1);
                                        
    $result_final .=  "<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=$prev\" title='Previous Page'></a>";
                                    }

                                    
    // start from / end to number of pages
                                    
    for($i $start$i <= $end$i++)
                                    {                                    
                                        
    // Build the number of pages as numbers
                                        
    if(($page) == $i){
                                            
    $result_final .= "$i";
                                        } else {
                                            
    $result_final .=  "<a href=".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=$i\" title='Page ".$i."'>$i</a>";
                                        }
                                    }

                                    
    // Build Next Link
                                    
    if($page $total_pages)
                                    {
                                        
    $next = ($page 1);
                                        
    $result_final .=  "<a href=".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=$next\" title='Next Page'></a>";
                                    }
                                    
                                    
    // Build last page link
                                    
    if($total_pages $max_results)
                                    {
                                        
    $result_final .=  "<a href=".$_SERVER['PHP_SELF']."?cid=$cid&back=$backpage&page=$total_pages\" title='Last Page'>last &raquo;</a>";
                                    }
                                    
                            
    $result_final .=  "</p>
                            </div>
                            <br />"
    ;
                            }
                            else
                            {
            
    $result_final .=  "\n"
                        } 
    I have serval Problems with my Code above they are:

    1. My $max_results its not showing the its only show 2 images per page
    2. My Pagination Script Its not displaying the next,previous,last links


    How can i fix these errors?

    Thanks

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello i have given here the Pagination Function and use of this function:
    PHP Code:
    <?php
        
    function PaginateData($start$perPage$total$page){
            if(
    $total >= 1){
                echo 
    "<b>";
                
    //for previous
                
    $previous $start $perPage;
                if(
    $start and $start < ($total $perPage))
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> ";
                else if(
    $start and $start >= ($total $perPage))
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> ";
                
    //complete previous
                
    echo "Page : | ";
                
    $l 1;
                for(
    $i 0$i $total$i $i $perPage){
                    if(
    $i != $start)
                        
    $a[$l] = "<a  href=\"$page&start=$i\">$l</a>&nbsp;";
                    else
                        
    $a[$l] = "$l&nbsp;";
                    
    $l++;
                }
                foreach(
    $a as $p=>$pp)
                    echo 
    $pp;
                
    //for next
                
    echo " | ";
                
    $next $start $perPage;
                if((
    $start == 0) and $total $perPage)
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>";
                else if(
    $start and $start < ($total $perPage))
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>";    
                
    //complete next
            
    }
            echo 
    "</b>";
        }

        require_once(
    '../configuration/configure_database.php');
        require_once(
    '../includes/library.inc.php');
        require_once(
    '../includes/class_database_connection.php');
        require_once(
    '../includes/charts.php');
        
        
    $dbcnx = new MysqlConnection($database);

        
    //paging
        
    $perPage 10;
        
    $total 0;
        if(isset(
    $_GET['start'])){$start $_GET['start'];}
        else{
    $start 0;}
    ?><table width="100%" border="0" align="center" cellspacing="0" class="TableStyle">
      <tr>
        <td colspan="2" align="center" style="border-top:1px #CCCCCC solid;">&nbsp;</td>
      </tr>
      <tr>
        <td width="400%" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="TableStyle" style="border:1px #996633 solid;">
          <tr class="TableStyle">
            <td width="2%" height="20" bgcolor="#996633" class="InnerTableHeader">&nbsp;</td>
            <td width="53%" bgcolor="#996633" class="InnerTableHeader"><strong>Product Name </strong></td>
            <td width="19%" bgcolor="#996633" class="InnerTableHeader">Product Price</td>
            <td width="14%" bgcolor="#996633" class="InnerTableHeader"><strong>Quantity</strong></td>
            <td width="12%" align="center" bgcolor="#996633" class="InnerTableHeader"><strong>Total</strong></td>
          </tr>
          <?php
            $sqlC 
    "SELECT * FROM tblproductdesc";
            
    $rsC mysql_query($sqlC) or die(mysql_error());
            
    $total1 mysql_num_rows($rsC);

            
    $sql "SELECT * FROM tblproductdesc ORDER BY PurchaseTime DESC LIMIT $start$perPage";
            
    $rs mysql_query($sql) or die(mysql_error());
            
    $ordertotal 0;
            
    $numRows mysql_num_rows($rs);
              if(
    $total1 >= 1){
              while(
    $rows mysql_fetch_array($rs)){
              
    $bgcolor = ($bgcolor == "#FFFFFF" ) ? "#EFEFEF" "#FFFFFF";
              
    ?>
          <tr bgcolor="<?php echo $bgcolor;?>">
            <td align="center">&nbsp;</td>
            <td><?php echo $rows['ProductName'];?></td>
            <td><?php echo number_format($rows['ProductPrice'], 2);?></td>
            <td><?php echo $rows['ProductQty'];?></td>
            <td><?php echo number_format($rows['ProductQty'] * $rows['ProductPrice'], 2);?></td>
          </tr>
          <?php $ordertotal += $rows['ProductQty'] * $rows['ProductPrice'];
          }
          
    ?>
          <tr>
            <td align="center" style="border-top:1px #CCCCCC solid;">&nbsp;</td>
            <td colspan="3" align="right" style="border-top:1px #CCCCCC solid;"><strong>Page Total : </strong></td>
            <td style="border-top:1px #CCCCCC solid;"><?php echo number_format($ordertotal2);?></td>
          </tr>
          <tr>
            <td align="center" style="border-top:1px #CCCCCC solid;">&nbsp;</td>
            <td colspan="3" align="right" style="border-top:1px #CCCCCC solid;"><strong>Grand OrderTotal : </strong> </td>
            <td style="border-top:1px #CCCCCC solid;"><?php echo number_format($gtotal2);?></td>
          </tr>
          <tr>
            <td colspan="5" align="center" style="border-top:1px #CCCCCC solid;"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="TableStyle">
                <tr>
                  <td width="29%" align="left"><?php
                      
    if($total1 >= 1){
                      if(
    $total1 $perPage){$perPage $total1;} 
                        echo 
    "Displaying " . ($start 1) . " - " . ($start $numRows) . " of " $total1;
                      }
                      
    ?>              </td>
                  <td width="71%" colspan="3" align="right"><?php PaginateData($start$perPage$total1"showsalesreport.php?cid=$cid");?></td>
                </tr>
            </table></td>
          </tr>
          <?php }else{?>
          <tr>
            <td align="center" colspan="5">No sales report found.</td>
          </tr>
          <?php ?>
        </table></td>
      </tr>
    </table>
    You can change the per page records to display as:
    PHP Code:
        //paging
        
    $perPage 10// change your per page records
        
    $total 0;
        if(isset(
    $_GET['start'])){$start $_GET['start'];}
        else{
    $start 0;} 
    I can't do anything more than this william232. If this is not what you are looking for, then i m sorry.
    Last edited by Raju Gautam; Dec 27, 2006 at 02:35.

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <form method="post" action="">
    <input name="cid" type="hidden" value="<? echo $cid?>">
    </form>
    <?php 
                
    include("dbconnect.php");
                
    $gQuery="SELECT * FROM gallery WHERE cid='$cid'"
                
    $rs=mysqli_query($con,$gQuery);
                if(!
    $rs
                { 
                    
    $dbError="Error:Failed to executing query".mysqli_error($con); 
                } 
                else 
                { 
                    
    $count=$rs->num_rows
                    if(
    $count>0
                    { 
                        
    print_r($data); 
                        
    $data=$rs->fetch_assoc(); 
                        
    $imagethumbnail=$data['imagethumbnail']; 
                    } 
                    else 
                    { 
                        
    print_r($data); 
                        echo 
    "<br/>Gallery Information Cannot be Found"
                    } 
                    echo 
    $cid;
    ?>
    <?php 
        
    function PaginateData($start$perPage$total$page){ 
            if(
    $total >= 1){ 
                echo 
    "<b>"
                
    //for previous 
                
    $previous $start $perPage
                if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                else if(
    $start and $start >= ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                
    //complete previous 
                
    echo "Page : | "
                
    $l 1
                for(
    $i 0$i $total$i $i $perPage){ 
                    if(
    $i != $start
                        
    $a[$l] = "<a  href=\"$page&start=$i\">$l</a>&nbsp;"
                    else 
                        
    $a[$l] = "$l&nbsp;"
                    
    $l++; 
                } 
                foreach(
    $a as $p=>$pp
                    echo 
    $pp
                
    //for next 
                
    echo " | "
                
    $next $start $perPage
                if((
    $start == 0) and $total $perPage
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>"
                else if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>";     
                
    //complete next 
            

            echo 
    "</b>"
        } 
        include(
    "dbconnect.php");
        
    //paging 
        
    $perPage 3
        
    $total 3
        if(isset(
    $_GET['start'])){$start $_GET['start'];} 
        else{
    $start 0;} 
    ?>
    <table> 
          <?php 
          error_reporting
    (E_ALL);
            
    $sqlC "SELECT * FROM Gallery";
            
    $rs=mysqli_query($con,$sqlC);
            if(!
    $rs)
            {
                echo 
    "Error:".mysqli_error($con);
            }
            else
            {
                  
    $sql "SELECT * FROM gallery WHERE cid='$cid'ORDER BY id DESC LIMIT $start$perPage";
                  
    $rs=mysqli_query($con,$sql);
                  if(!
    $rs)
                  {
                      echo 
    "Error:".mysqli_error($con);
                  }
                  else
                  {
                        
    $count=$rs->num_rows
                        if(
    $count>0
                    { 
                            while(
    $data=$rs->fetch_assoc()) 
                            { 
                                echo 
    "<tr><td><img src=gallery/".$data['imagethumbnail']." width=\"100px\" height=\"100px\"></td><td>".$data['description']."</td></tr><br/>"
                             } 
                    }
            }
          
    ?> 

          <tr> 
          </tr> 
          <tr> 
            <td colspan="5" align="center" style="border-top:1px #CCCCCC solid;"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="TableStyle"> 
                <tr> 
                  <td width="29%" align="left"><?php 
                      
    if($total1 >= 1){ 
                      if(
    $total1 $perPage){$perPage $total1;} 
                        echo 
    "Displaying " . ($start 1) . " - " . ($start $numRows) . " of " $total1
                      } 
                      
    ?></td> 
            </table>
        </td> 
        </tr> 
                          <?php }
                        }
    ?> 
       </table>
       </td> 
      </tr> 
    </table>
    That is my code its coming back with the cid being not found is there somthing wrong that i am doing?

    How can i get my cid to be shown?

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok change this line according to your cid passing URL while calling:
    PHP Code:
    <td width="71%" colspan="3" align="right"><?php PaginateData($start$perPage$total1"showsalesreport.php?cid=$cid");?>
    to
    PHP Code:
    td width="71%" colspan="3" align="right"><?php PaginateData($start$perPage$total1"yourfilename.php?cid=$cid");?>
    it should work. Please use the query executing exactly same as i have done. You have to run your query two times;
    One for getting all the rows and one for limited (paging) rows.

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok still getting cid heres my code

    PHP Code:
    <form method="post" action=""> 
    <input name="cid" type="hidden" value="<? echo $cid?>"> 
    </form> 
    <?php 
                
    include("dbconnect.php"); 
                
    $gQuery="SELECT * FROM gallery WHERE cid='$cid'"
                
    $rs=mysqli_query($con,$gQuery); 
                if(!
    $rs
                { 
                    
    $dbError="Error:Failed to executing query".mysqli_error($con); 
                } 
                else 
                { 
                    
    $count=$rs->num_rows
                    if(
    $count>0
                    { 
                        
    print_r($data); 
                        
    $data=$rs->fetch_assoc(); 
                        
    $imagethumbnail=$data['imagethumbnail']; 
                    } 
                    else 
                    { 
                        
    print_r($data); 
                        echo 
    "<br/>Gallery Information Cannot be Found"
                    } 
                    echo 
    $cid
    ?> 
    <?php 
        
    function PaginateData($start$perPage$total$page){ 
            if(
    $total >= 1){ 
                echo 
    "<b>"
                
    //for previous 
                
    $previous $start $perPage
                if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                else if(
    $start and $start >= ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                
    //complete previous 
                
    echo "Page : | "
                
    $l 1
                for(
    $i 0$i $total$i $i $perPage){ 
                    if(
    $i != $start
                        
    $a[$l] = "<a  href=\"$page&start=$i\">$l</a>&nbsp;"
                    else 
                        
    $a[$l] = "$l&nbsp;"
                    
    $l++; 
                } 
                foreach(
    $a as $p=>$pp
                    echo 
    $pp
                
    //for next 
                
    echo " | "
                
    $next $start $perPage
                if((
    $start == 0) and $total $perPage
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>"
                else if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>";      
                
    //complete next 
            

            echo 
    "</b>"
        } 
        include(
    "dbconnect.php"); 
        
    //paging 
        
    $perPage 3
        
    $total 3
        if(isset(
    $_GET['start'])){$start $_GET['start'];} 
        else{
    $start 0;} 
    ?> 
    <table> 
          <?php 
          error_reporting
    (E_ALL); 
            
    $sqlC "SELECT * FROM Gallery"
            
    $rs=mysqli_query($con,$sqlC); 
            if(!
    $rs
            { 
                echo 
    "Error:".mysqli_error($con); 
            } 
            else 
            { 
                  
    $sql "SELECT * FROM gallery WHERE cid='$cid'ORDER BY id DESC LIMIT $start$perPage"
                  
    $rs=mysqli_query($con,$sql); 
                  if(!
    $rs
                  { 
                      echo 
    "Error:".mysqli_error($con); 
                  } 
                  else 
                  { 
                        
    $count=$rs->num_rows
                        if(
    $count>0
                    { 
                            while(
    $data=$rs->fetch_assoc()) 
                            { 
                                echo 
    "<tr><td><img src=gallery/".$data['imagethumbnail']." width=\"100px\" height=\"100px\"></td><td>".$data['description']."</td></tr><br/>"
                             } 
                    } 
            } 
          
    ?> 

          <tr> 
          </tr> 
          <tr> 
            <td colspan="5" align="center" style="border-top:1px #CCCCCC solid;"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="TableStyle"> 
                <tr> 
                  <td width="29%" align="left"><?php 
                      
    if($total1 >= 1){ 
                      if(
    $total1 $perPage){$perPage $total1;} 
                        echo 
    "Displaying " . ($start 1) . " - " . ($start $numRows) . " of " $total1
                      } 
                      
    ?></td>
                      <td width="71%" colspan="3" align="right"><?php PaginateData($start$perPage$total1"pages4.php?cid=$cid");?></td>
            </table> 
        </td> 
        </tr> 
                          <?php 
                        }
    ?> 
       </table> 
       </td> 
      </tr> 
    </table>
    What am i doing wrong?

  6. #6
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cid not working with Pagination System

    I have Found a pagination system that works great now what i want is to display everything of the cid 1 and paginate everything with cid =1 but its displaying everything heres my code

    PHP Code:
    <?php
    /*database conection settings*/
    include("dbconnect.php");
    echo 
    $cid;
    $cid=($_GET['cid']);
                                if(
    $_GET['cid'])
                                {
                                    
    $cQuery="SELECT * FROM gallery WHERE cid='$cid'";
                                    
    $result=mysqli_query($con,$cQuery);
                                    if(!
    $result)
                                    {
                                        echo 
    "Error:".mysqli_error($con);
                                    }
                                    else
                                    {
                                        
    $count=$result->num_rows;
                                        if(
    $count>0)
                                        {
                                            while(
    $data=$result->fetch_assoc())
                                            {
                                                
    $cid=$data['cid'];
                                                
    $imagethumbnail=$data['imagethumbnail'];
                                            }
                                        }
                                        else
                                        {
                                        echo 
    "<br/>There is no Gallery Informartion Found<br/>";
                                        }
                                    }
                                }
    ?>
    <input type="hidden" name="cid" value="<?php $cid ?>">
    <?php
    $num 
    $_GET['num'];//Get the numeration of the page
    if(empty($num)){//if the numeration is empty
    $num 1;//the numeration is 1
    };
    $limit 3;//Sets the limit of results to display in each page, change if you want.
    /*
    The query will start selecting the numeration, for example 2, less 1, that would be 1
    * the limits of results to show per page, 2 in this case so it would be 1*2 = 2, it will
    start from 2 ;) if the limit would be 5 and the numeration would be 3 if would be (3-1)*5 = 10
    */
    $start = ($num-1)*$limit;
    $start round($start,0);//rounds the result
    /*
    This query will select the contrene FROM the start and with a limit of 2, in this case,
    because the variable $limit is 2
    You can add a WHERE something= '$something' for example, or delete the ORDER by `id`, or change it,
    etc
    */
    $query "SELECT * FROM gallery ORDER by `id` LIMIT $start$limit";
    $result mysqli_query($con,$query);//now it makes the query and names it as result
    /*
    While will repeat this query and mysql_fect_array allow me array the content
    */
    while ($data mysqli_fetch_array($result)){
    echo 
    "<tr><td><img src=gallery/".$data['imagethumbnail']." width=\"100px\" height=\"100px\"></td><td>".$data['description']."</td></tr><br/>";//Echoes the content
    };
    $totalpages mysqli_num_rows(mysqli_query($con,"SELECT * from `gallery`"));//Get the total number of results
    /*
    Total resutls/ the limit, in this example is 2, so if there are 10 total result and the limit is 2
    there will be 5 pages.
    */
    $totalpages $totalpages $limit;
    $totalpages round($totalpages,0);
    $c 0;//The variable c is 0
    echo "<br>";//make a <br> to separate the results from the [1][2]...
    while($c<$totalpages){//while c is < than the total pages
    $page $c 1;//sets the variable $page as 0 + 1 = 1
    if($_GET['num']==$page){//Gets the number of the page and if its the same that the page
    echo "[$page] ";//its only echoes the page, not the url to this page
    }else{//else
    echo "<a href=?cid=".$cid."&num=$page>[$page] </a>";//it echoes the url to the page
    }
    $c $c+1;
    }
    echo 
    "<br>".$totalpages." Pages in total.";//echoes the total pages
    ?>

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where does your $cid come from? If it comes from URL then do at the very beginning as $_GET['cid'] or if it comes from any other forms then $_POST[cid].
    do this in the top of your page as
    PHP Code:
    $cid $_GET['cid']; 

  8. #8
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have attempted to put where cid='$cid' into the query the limits the query but doesnt do anything gives me a blank screen back.

  9. #9
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now its displaying stuff in cid=1 but now its not showing the pagination links how come heres wat i have right now

    PHP Code:
    <form method="post" action=""> 
    <input name="cid" type="hidden" value="<? echo $cid?>"> 
    </form> 
    <?php 
                $cid 
    $_GET['cid']; 
                include(
    "dbconnect.php"); 
                
    $gQuery="SELECT * FROM gallery WHERE cid='$cid'"
                
    $rs=mysqli_query($con,$gQuery); 
                if(!
    $rs
                { 
                    
    $dbError="Error:Failed to executing query".mysqli_error($con); 
                } 
                else 
                { 
                    
    $count=$rs->num_rows
                    if(
    $count>0
                    { 
                        
    print_r($data); 
                        
    $data=$rs->fetch_assoc(); 
                        
    $imagethumbnail=$data['imagethumbnail']; 
                    } 
                    else 
                    { 
                        
    print_r($data); 
                        echo 
    "<br/>Gallery Information Cannot be Found"
                    } 
                    echo 
    $cid
    ?> 
    <?php 
        
    function PaginateData($start$perPage$total$page){ 
            if(
    $total >= 1){ 
                echo 
    "<b>"
                
    //for previous 
                
    $previous $start $perPage
                if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                else if(
    $start and $start >= ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$previous\" title=\"Previous\">&laquo; Previous</a> "
                
    //complete previous 
                
    echo "Page : | "
                
    $l 1
                for(
    $i 0$i $total$i $i $perPage){ 
                    if(
    $i != $start
                        
    $a[$l] = "<a  href=\"$page&start=$i\">$l</a>&nbsp;"
                    else 
                        
    $a[$l] = "$l&nbsp;"
                    
    $l++; 
                } 
                foreach(
    $a as $p=>$pp
                    echo 
    $pp
                
    //for next 
                
    echo " | "
                
    $next $start $perPage
                if((
    $start == 0) and $total $perPage
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>"
                else if(
    $start and $start < ($total $perPage)) 
                    echo 
    " <a href=\"$page&start=$next\" title=\"Next\">Next &raquo;</a>";      
                
    //complete next 
            

            echo 
    "</b>"
        } 
        include(
    "dbconnect.php"); 
        
    //paging 
        
    $perPage 3
        
    $total 3
        if(isset(
    $_GET['start'])){$start $_GET['start'];} 
        else{
    $start 0;} 
    ?> 
    <table> 
          <?php 
          error_reporting
    (E_ALL); 
            
    $sqlC "SELECT * FROM Gallery"
            
    $rs=mysqli_query($con,$sqlC); 
            if(!
    $rs
            { 
                echo 
    "Error:".mysqli_error($con); 
            } 
            else 
            { 
                  
    $sql "SELECT * FROM gallery WHERE cid='$cid'ORDER BY id DESC LIMIT $start$perPage"
                  
    $rs=mysqli_query($con,$sql); 
                  if(!
    $rs
                  { 
                      echo 
    "Error:".mysqli_error($con); 
                  } 
                  else 
                  { 
                        
    $count=$rs->num_rows
                        if(
    $count>0
                    { 
                            while(
    $data=$rs->fetch_assoc()) 
                            { 
                                echo 
    "<tr><td><img src=gallery/".$data['imagethumbnail']." width=\"100px\" height=\"100px\"></td><td>".$data['description']."</td></tr><br/>"
                             } 
                    } 
            } 
          
    ?> 

          <tr> 
          </tr> 
          <tr> 
            <td colspan="5" align="center" style="border-top:1px #CCCCCC solid;"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="TableStyle"> 
                <tr> 
                  <td width="29%" align="left"><?php 
                      
    if($total1 >= 1){ 
                      if(
    $total1 $perPage){$perPage $total1;} 
                        echo 
    "Displaying " . ($start 1) . " - " . ($start $numRows) . " of " $total1
                      } 
                      
    ?></td>
                      <td width="71%" colspan="3" align="right"><?php PaginateData($start$perPage$total1"pages4.php?cid=$cid");?></td>
            </table> 
        </td> 
        </tr> 
                          <?php 
                        }
    ?> 
       </table> 
       </td> 
      </tr> 
    </table>
    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •