Jump to content

Number of products per line and pagination


nzizo

Recommended Posts

Hello,

 

I have this loop script to load 3 products per line:

<?
$page2 = $_GET['page2'];
$display = 3;
$cols = 0;
echo "<table border=\"0\" cellpadding=\"10\" cellspacing=\"20\">";
include("inc/connect.php");
$result = mysql_query("SELECT * FROM proionta WHERE ID_CATEGORY = '$page2' ORDER BY TAX");
while($fetched = mysql_fetch_array($result)){
if($cols == 0){
	echo "<tr>\n";
}
// put what you would like to display within each cell here
echo "<td align=\"center\"><a href=\"images-proionta/".$fetched['IMAGE_BIG']."\" rel=\"lightbox\"><img src=\"images-proionta/".$fetched['IMAGE']."\" width=\"120\" height=\"70\" border=\"0\" class=\"homeimages-border\"></a></td>\n";
$cols++;
if($cols == $display){
	echo "</tr>\n";
	$cols = 0;
}
}
// added the following so it would display the correct html
if($cols != $display && $cols != 0){
$neededtds = $display - $cols;
for($i=0;$i<$neededtds;$i++){
	echo "<td></td>\n";
}
 echo "</tr></table>";
} else {
echo "</table>";
}
?>		  

 

And the pagination script for the same products:

<?
include("inc/connect.php");
$page2 = $_GET['page2'];
$limit = 5;
$query_count = "SELECT * FROM proionta WHERE ID_CATEGORY = '$page2' ORDER BY TAX";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$page = $_GET['page'];
if(empty($page))
$page = 1;
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM proionta WHERE ID_CATEGORY = '$page2' ORDER BY TAX LIMIT $limitvalue, $limit ";
$result = mysql_query($query);
$count_result = mysql_num_rows($result);
while ($today = mysql_fetch_array($result)){
echo ("<tr>
<td width=\"29%\" height=\"100\" align=\"center\" valign=\"middle\" bgcolor=\"#B0C4E6\" class=\"maintext\">
<a href=\"images-proionta/$today[5]\" rel=\"lightbox\"><img src=\"images-proionta/$today[4]\" width=\"120\" height=\"70\" border=\"0\" class=\"homeimages-border\"></a><br></td>
<td width=\"71%\" height=\"100\" align=\"left\" valign=\"middle\" bgcolor=\"#B0C4E6\" class=\"maintext\">$today[3]</td>
</tr>");
}
$numofpages = ceil($totalrows / $limit);
$from=$limit*$page-$limit+1;
$to=$from + $count_result-1;
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		<tr>";if($numofpages>1){echo"<td width=\"100%\" align=\"right\">";}
if($page != 1){
$pageprev = $page - 1;
echo("<a href=\"$PHP_SELF?page=$pageprev&page2=$page2\" class=\"menulink\"><font color=\"#000066\" size=\"2\" face=\"Tahoma\">Previous</font></a> ");
}
for($i = 1; $i <= $numofpages; $i++){
if($numofpages>1){
if($i == $page)
echo(" ".$i." ");
else
echo(" <a href=\"$PHP_SELF?page=$i&page2=$page2\" class=\"menulink\"><font color=\"#000066\" size=\"2\" face=\"Tahoma\">$i</font></a> ");
}}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo("<a href=\"$PHP_SELF?page=$pagenext&page2=$page2\" class=\"menulink\"><font color=\"#000066\" size=\"2\" face=\"Tahoma\">Next</font></a>");
}
echo"</td></tr></table><br>"; 			
?>		  

 

So, I want to make this 2 scripts to work together, for example 3 products per line and pagination.

 

Thanks in advance,

Nick

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.