Hey guys. I used the tutorial for the Multicolumn output using php and mysql and a pagination script. The thing is that the Multicolumn output script doesn't display corectly the limited the results from the pagination script. It displays the first 6 items I specified but it then loops until it reaches the last column. I can't explain it very well so I'll enclose the code so you may test it and see what I mean.
session_start();
$title = "Shops Network";
include 'inc/header.inc.php';
include 'inc/config.inc.php';
$columns = 2;
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
if(!isset($_GET['nomos'])){
$nomos = 'Athens';
} else {
$nomos = $_GET['nomos'];
}
$max_results = 6;
$from = (($page * $max_results) - $max_results);
$limitvalue = $page * $limit - ($limit);
$sql = "SELECT * FROM ".$table[3]." WHERE nomos = '".$nomos."' ORDER BY sid ASC LIMIT $from, $max_results";
//echo $sql;
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as total FROM ".$table['3']." WHERE nomos = '".$nomos."'"),0);
$rows = ceil($total_results / $columns);
$total_pages = ceil($total_results / $max_results);
echo "<div align=\"center\">\n";
if($total_results > 0) {
if ($total_results == 1 || $total_results < 2) {
$shops = "shop";
$found = "found";
}
else {
$shops = "shops";
$found = "found";
}
echo $found . " " . $total_results . " " . $shops . ".<br><br>";
echo "<strong>Results</strong><br><br></div>\n";
echo "<TABLE BORDER=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
for($i = 0; $i < $rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>\n";
}
echo "<TD>\n"
."<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=30%>Store: </td><td>".$row['store']."</td>\n"
."</tr>\n"
."<tr>\n"
."<td width=\"120\" valign=\"top\">Address: </td><td>".$row['address']."</td>\n"
."</tr>\n"
."<tr>\n"
."<td valign=\"top\">Area: </td><td>".$row['area']."</td>\n"
."</tr>\n"
."<tr>\n"
."<td valign=\"top\">Phone: </td><td>".$row['phone']."</td>\n"
."</tr>\n"
."<tr>\n"
."<tr>\n"
."<td valign=\"top\">FAX: </td><td>".$row['fax']."</td></tr>\n"
."<tr>\n"
."<td valign=\"top\">E-Mail: </td><td><b><a href=\"mailto:".$row['e-mail']."\">".$row['e-mail']."</a></b></td>\n"
."</tr>\n"
."</table> \n"
."</TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>\n";
}
}
echo "</table>\n"
."Pages: \n";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<b><a href=\"".$_SERVER['PHP_SELF']."?nomos=".$nomos."&page=$prev\">«</a></b>\n";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font color=\"#FF6600\"><b>$i</b></font> \n";
} else {
echo " <b><a href=\"".$_SERVER['PHP_SELF']."?nomos=".$nomos."&page=$i\">$i</a> </b>\n";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<b><a href=\"".$_SERVER['PHP_SELF']."?nomos=".$nomos."&page=$next\">»</a></b>\n";
}
echo "<br><center><a href=\"index.php\">Go Back</a>";
echo "</center><br>\n";
} else {
echo "No results where found.\n";
}
include 'inc/footer.inc.php';