I am trying to format my SQL results into a table.....
First of all i can get my script to display results, but cant format it onto 3 rows and then start a new 3 rows.
this code is pulling an array from a previous page.........
<?
if (isset($_POST['print']))
{
foreach ($_POST['print'] as $value) {
echo "<table><tr>";
$query = "SELECT * FROM flyers where `id` = '".$value."' ORDER BY id desc";
$result = mysql_query($query) or die("Query failed");
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
$x++;
if ($x == 1) { $id = $col_value; }
if ($x == 2) { $name = $col_value; }
if ($x == 3) { $age = $col_value; }
if ($x == 4) { $mobile = $col_value; }
if ($x == 5) { $email = $col_value; }
if ($x == 6) { $school = $col_value; }
if ($x == 7) { $address = $col_value; }
if ($x == 8) { $comments = $col_value; }
if ($x == 9) { $powerhouse = $col_value; }
if ($x == 10) { $assigned = $col_value; }
if ($x == 11) { $emailed = $col_value; }
if ($x == 12) { $posted = $col_value; }
}
print "<td>";
print "<tr><td class=text valign=top><b>$name</b></td></tr>\n";
print "<tr><td class=text valign=top>$address</td></tr>\n";
print "<tr><td height=20></td></tr></td>\n";
$x = 0;
}
echo "</tr></table>";
}
}
else
{
echo 'you did not check any rows';
}
?>
First of all i was recommended to execute the above code differently, this was the code that was suggested to me
$query = 'SELECT * FROM flyers WHERE `id` IN(' . implode(',', $_POST['print']) . ') ORDER BY id DESC';
But i cant for the life of me implement that suggestion into my code.
Ok so imagine the code was implemented, the next problem is making the above html, display across 3 rows and then start a new 3 rows below.
i found this code that i think does that but i tried and failed to implement it
$i=1; // Most crucial part!!
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
// Display your stuff
if($i%3==0){ echo '</tr><tr>'; }
$i++; // Increment the counter
}
any help would be grately appricated! i have been on this all day now and its starting to drive me nuts! especially when i know what im trying to do but cant do it due to lack of knowledge!
Thanks!
Dave