Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to add pagination + export to this...

    I'm having problems adding pagination and export to my website. Each of my pages will display 60 rows from my database in two tables (30 rows per table) by using limits. I would like to create an export to text file for each page which combines both tables (so all 60 rows per page) and only of the first two columns (item1+item2). My database will have a few thousands entries so I need to also add pagination...however I'm having issues doing this because I am using two tables per page with limits..I'm attaching a bit of code which consists of three files:

    MAIN.PHP:

    Code:
    <?php
    include ("mysql.php");
    
    $result = mysql_query("SELECT * FROM TEST$$$$ Limit 0,30")or die(mysql_error()); 
    include ("grid.php"); 
    include ("ads.php");
    $result = mysql_query("SELECT * FROM TEST$$$$ Limit 30,30")or die(mysql_error()); 
    include ("grid.php");
    include ("ads.php"); 
    ?>
    MYSQL.PHP:
    Code:
    <?
    mysql_connect("localhost", "user", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());
    ?>
    GRID.PHP:
    Code:
    <link rel="stylesheet" type="text/css" href="grid.css" /> 
    <?
    $aStyle = array("background-color:#FFFFFF   ", "background-color:#00FF66   "); 
    $iStyle = 0;
    	
    	
    	echo "<table summary='testtable'>";
    	echo "<thead>";
    	echo "<tr> <th scope 'col'>item1</th> <th scope 'col'>item2</th> <th scope 'col'>item3</th> <th scope 'col'>item4</th> </tr>";
    	echo "</thead>";
    
    
    while ($row = mysql_fetch_array($result)) { 
        echo "<tbody bgcolor='#FFCC66'>";
    	echo "<tr style=\"".$aStyle[++$iStyle%2]."\"><td id='item1'>"; 
    	echo $row['item1'];
    	echo "</td><td>"; 
    	echo $row['item2'];
    	echo "</td><td>"; 
    	echo date('F d, Y ');
    	echo "</td><td id='item4'>";
    	echo "<span class='sp_link'>item4</span>";
    	echo "</td></tr>"; 
    	echo "</tbody>";
    	
    	}	
    echo "</table>";
    ?>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't really understand why you need the pagination for the textfiles, but can't you simply run one query with a " limit 60" clause, and then inside your while loop have a countervalue that automatically starts a new table after 30 records. like
    PHP Code:
    $tablehead '<table summary="testtable">
                        <thead>
                          <tr>
                             <th scope "col">item1</th>
                             <th scope "col">item2</th>
                             <th scope "col">item3</th>
                             <th scope "col">item4</th>
                          </tr>
                        </thead>
                        <tbody bgcolor="#FFCC66">'
    ;
    $tablefoot '</tbody></table>';
        
    echo 
    $tablehead;
    $i 0;
    $filecontent '';
    while (
    $row mysql_fetch_array($result)) { 
                 if (
    $i == 30){
                    echo 
    $tablefoot$tablehead
                 }      
                 echo 
    "<tr style=\"".$aStyle[++$iStyle%2]."\"><td id='item1'>"
        echo 
    $row['item1'];
        echo 
    "</td><td>"
        echo 
    $row['item2'];
        echo 
    "</td><td>"
        echo 
    date('F d, Y ');
        echo 
    "</td><td id='item4'>";
        echo 
    "<span class='sp_link'>item4</span>";
        echo 
    "</td></tr>"
                
    $filecontent .= $row['item1'] . ', ' $row['item2'];
    }
    echo 
    $tablefoot
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That code doesn't do the job. It would prob be easier to just select the entire data from TEST$$$$ and have code that displays two tables per page with 30 rows per table in chronological order across "X" amount of pages. The number of pages would be automatically generated based on how many rows TEST$$$$ contains. That's where pagination would be used to only display two tables per page again across "X" amount of pages.. The data will fluctuate in size and therefore the pagination will compensate for an increase/decrease in pages based on the entire contents of TEST$$$$. Inbetween each table per page, I will need to add "ads.php".

    Sorry if I wasn't clear enough before but my limited knowledge is a huge barrier and extremely frustrating. Thanks for the help!


  •  

    Posting Permissions

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