Forum Moderators: coopster

Message Too Old, No Replies

Help with Column Ordering and Pagination

         

t112071

6:12 am on Apr 12, 2008 (gmt 0)

10+ Year Member



I'm not very experienced with PHP. I have the following code which includes Pagination. It works great except it's listing each result vertically down the page. I would like to show the results in a table, the table being 4 cells across with a result in each cell. Is there any possible way of doing this?

My code:


if (!(isset($pagenum)))
{
$pagenum = 1;
}

$data = mysql_query("SELECT * FROM minions WHERE minion_cat='Arid'") or die(mysql_error());
$rows = mysql_num_rows($data);

$page_rows = 15;

$last = ceil($rows/$page_rows);

if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

$data_p = mysql_query("SELECT * FROM minions WHERE minion_cat='Arid' ORDER BY minion_name $max") or die(mysql_error());

while($info = mysql_fetch_array( $data_p ))
{
echo "<img src='/images/minions/";
Print $info['minion_image'];
echo "'>";
echo "<br>";
Print $info['minion_name'];
echo "<br>";
}
echo "<p>";

echo " --Page $pagenum of $last-- <p>";

if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}

echo " ---- ";

if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}

tutorial

9:05 am on Apr 12, 2008 (gmt 0)

10+ Year Member



Yes, there is a way to put results into tables. You should put a code which print out the page numbers between <table> and </table>. The example looks like this:


<?php
echo '<table>';

while($row=mysql_fetch_array($query)){
echo '<tr><td><a href="?page=2">'.$row['headline'].'</a><td></tr>';
}

echo '</table>';
?>

You just have to adjust it to your code.