...

View Full Version : how to add pagination + export to this...



sammy
08-08-2006, 07:30 PM
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:



<?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:


<?
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
?>


GRID.PHP:


<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>";
?>

raf
08-09-2006, 07:40 AM
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


$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;

sammy
08-09-2006, 06:53 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum