I am attempting to add script to limit the number of images displayed per page. The images to be displayed in 2 columns. The script I have used I obtained from searching "PHP Pagination" via Google, it seemed to work fine until I tried to added the code to put the images diplayed into 2 columns. Each set of code worked OK on its own! Any help would be appreciated.
[CODE=php]
<?php
$Host="mysql1.n amesco.net";
$User="usedcars gbco";
$Password="0312 55";
$DBName = "usedcarsgb co";
$TableName = "VehicleSto ck";
$TablePhoto = "cpg140_picture s";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.Re gNo = cpg140_pictures .title ORDER BY CarID DESC";
$Result = mysql_db_query ($DBName, $Query, $Link);
$max = 4;
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['RegNo'];
$sql = mysql_query("SE LECT * FROM VehicleStock");
while($r = mysql_fetch_arr ay($sql))
{
$RegNo = $r['RegNo'];
$Price = $r['Price'];
echo "<div><p>$RegNo </p><p>$Price</p></div>";
}
}else{
$sql = mysql_query("SE LECT * FROM VehicleStock LIMIT ".$limits.",$ma x") or die(mysql_error ());
$totalres = mysql_result(my sql_query("SELE CT COUNT(RegNo) AS tot FROM VehicleStock"), 0);
$totalpages = ceil($totalres / $max);
echo "<table align=center><t r><td>Reg No</td><td>Retail Price</td></tr><tr>";
$_counter = -1;
$_cols = 2;
{
$id = $r['RegNo'];
$RegNo = $r['RegNo'];
$Price = $r['Price'];
//(NEXT 28 LINES OF SCRIPT DISPLAY IMAGES IN 2 COLUMNS)
$_pos = ( ++$_counter % $_cols );
if( $_pos === 0 )
{
echo '
<tr>';
}
echo "<tr><td><a href='VehicleDe tail.php?act=vi ew&RegNo=$id&Pr ice=$Price'>
<img border='0'alt=' Click for car details' src=gallery/albums/userpics/10001/$RegNo.jpg></a></td><td>£$Price</td>";
}
echo "</tr></table>";
if( $_pos === $_cols - 1 )
{
echo '
</tr>';
}
}
if( $_counter % $_cols !== $_cols - 1 )
{
do
{
echo '
<td style="visibili ty: hidden"> </td>';
}
while( ++$_counter % $_cols !== $_cols - 1 );
echo '
</tr>';
//END OF IMAGE DISPLAY SCRIPT
}
for($i = 1; $i <= $totalpages; $i++){
echo "<a href='StockTest .php?p=$i'>$i</a>|";
}
?>
</body>
</html>
[/CODE]
[CODE=php]
<?php
$Host="mysql1.n amesco.net";
$User="usedcars gbco";
$Password="0312 55";
$DBName = "usedcarsgb co";
$TableName = "VehicleSto ck";
$TablePhoto = "cpg140_picture s";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.Re gNo = cpg140_pictures .title ORDER BY CarID DESC";
$Result = mysql_db_query ($DBName, $Query, $Link);
$max = 4;
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['RegNo'];
$sql = mysql_query("SE LECT * FROM VehicleStock");
while($r = mysql_fetch_arr ay($sql))
{
$RegNo = $r['RegNo'];
$Price = $r['Price'];
echo "<div><p>$RegNo </p><p>$Price</p></div>";
}
}else{
$sql = mysql_query("SE LECT * FROM VehicleStock LIMIT ".$limits.",$ma x") or die(mysql_error ());
$totalres = mysql_result(my sql_query("SELE CT COUNT(RegNo) AS tot FROM VehicleStock"), 0);
$totalpages = ceil($totalres / $max);
echo "<table align=center><t r><td>Reg No</td><td>Retail Price</td></tr><tr>";
$_counter = -1;
$_cols = 2;
{
$id = $r['RegNo'];
$RegNo = $r['RegNo'];
$Price = $r['Price'];
//(NEXT 28 LINES OF SCRIPT DISPLAY IMAGES IN 2 COLUMNS)
$_pos = ( ++$_counter % $_cols );
if( $_pos === 0 )
{
echo '
<tr>';
}
echo "<tr><td><a href='VehicleDe tail.php?act=vi ew&RegNo=$id&Pr ice=$Price'>
<img border='0'alt=' Click for car details' src=gallery/albums/userpics/10001/$RegNo.jpg></a></td><td>£$Price</td>";
}
echo "</tr></table>";
if( $_pos === $_cols - 1 )
{
echo '
</tr>';
}
}
if( $_counter % $_cols !== $_cols - 1 )
{
do
{
echo '
<td style="visibili ty: hidden"> </td>';
}
while( ++$_counter % $_cols !== $_cols - 1 );
echo '
</tr>';
//END OF IMAGE DISPLAY SCRIPT
}
for($i = 1; $i <= $totalpages; $i++){
echo "<a href='StockTest .php?p=$i'>$i</a>|";
}
?>
</body>
</html>
[/CODE]
Comment