Hi all,
I tried to use weedpackets pagination solution from here but I need to get multiple sets of data from my query and also needed to pass some data to the result set, so I ended up making up my own pagination/array loop.
It is close to doing what I need with one exception. I needed to set the values of the array items to start at 1 instead of 0 (zero) for some loops I am doing on the next form. I am manually assigning the IDs and thats where the trouble begins.
So when I build my table, I get back the correctly listed items in order, but I am stuck trying to get the ID's ($ID) correctly matched to the products.
What I am currently getting is the IDs are assigned row by row (left to right, top to bottom) and I need them assigned columns (top to bottom, left to right).
Currently I have..
1-2-3
4-5-6
7-8-9
And I need...
1-4-7
2-5-8
3-6-9
Here is the code I am using ...
//connect to MySQL
include('conn.php');// Select the DB
$db_selected=mysql_select_db("db");
if(!$db_selected)
{
die(mysql_error());
}
$name = array();
$sql = "SELECT * FROM table WHERE SiteEnabled='1' AND Path='1' ORDER BY DateAdded DESC";
// We do the query, and find out how many items we'll need to list.
$result = mysql_query($sql);
// Define whats left and right for columns
$num = mysql_num_rows($result);
$left = ceil($num/3); // Define the left column for reference and the loop below
// Set up the array to hold the items
$items = array(); // Get all rows into array
while($row = mysql_fetch_array($result))
{
$items[] = $row;
// $x++;
}
//now start the table (HTML)
$ID = 1; //set the start ID for the Products loop
echo '<table>';
for($i=0; $i<$left;$i++)
{
$left_item = $items[$i];
$mid_item = $items[$i+$left];
$right_item = $items[$i+$left+$left];
echo '<tr>';
//------------------------1st column start----------------------------------//
if(!empty($left_item['Name']))
{
echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">';
echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$left_item['SKU'].'"';
if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser
{
echo ' checked>';
} else {
echo ' >';
}
echo htmlstripline($left_item['Name']);
echo '</td>';
} else {
echo '<td> </td>';
}
$ID++;
//------------------------1st column end----------------------------------//
//------------------------2nd column start----------------------------------//
if(!empty($mid_item['Name']))
{
echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">';
echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$mid_item['SKU'].'"';
if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser
{
echo ' checked>';
} else {
echo ' >';
}
echo htmlstripline($mid_item['Name']);
echo '</td>';
} else {
echo '<td> </td>';
}
$ID++;
//------------------------2nd column end----------------------------------//
//------------------------3rd column start----------------------------------//
if(!empty($right_item['Name']))
{
echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">';
echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$right_item['SKU'].'"';
if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser
{
echo ' checked>';
} else {
echo ' >';
}
echo htmlstripline($right_item['Name']);
echo '</td>';
} else {
echo '<td> </td>';
}
$ID++;
//------------------------3rd column end----------------------------------//
echo '</tr>';
}
echo '</table>';
//-------------------------------- End dynamic loop --------------------------------//
As always, I appreciate the help,
regards,
Don