Page 1 of 1

Formatting SQL Results

Posted: Mon May 10, 2010 4:52 am
by indyboy
Hey all

ive been trying to figure this out for a while now and my brains gone into meltdown. :banghead:

I want to format the results of an sql query so that it alternates the order each time it loops through the array

for example displays

image price description
description price image
then back to the first order

Anybody got any ideas :D

Cheers

Re: Formatting SQL Results

Posted: Mon May 10, 2010 8:25 am
by mikosiko
post the code that you have so far and will move from there

Re: Formatting SQL Results

Posted: Mon May 10, 2010 8:44 am
by indyboy
im not great at explaining so heres a picture of the layout im looking for

Image

this is the code ill be working on

Code: Select all

while($row = mysql_fetch_array($query))
{
echo "<table width='100%' border='1'>";
echo "<tr><td>";
echo $row['make']; 
echo "</td></tr>";
echo "<tr><td>";
echo $row['model']; 
echo "</td></tr>";
echo "<tr><td>";
echo " £"; 
echo $row['price']; 
echo "</td></tr>";


if ($row['image_name'])
{

$imageDir = "images/";

$img = $imageDir . $row['image_name'];
echo "<tr><td>";

echo "<centre><img src='$img'>";
echo "</td></tr>";
}
echo"</table>";
echo"<br/>";

cheers

Re: Formatting SQL Results

Posted: Mon May 10, 2010 8:55 am
by mikosiko

Re: Formatting SQL Results

Posted: Mon May 10, 2010 9:04 am
by indyboy
cheers for that

would i not still need to set up some kind of variable to alternate between the styles like this i found

Code: Select all

$i = 0; 
while( /* retrieve data from SQL */ ) { 
  if($i++ % 2 == 0) 
    echo "Odd row\n"; 
  else 
    echo "Even Row\n"; 
} 
i just dunno where or how to link the style to the odd and even rows

Re: Formatting SQL Results

Posted: Mon May 10, 2010 9:53 am
by mikosiko
indyboy wrote: would i not still need to set up some kind of variable to alternate between the styles like this i found

Code: Select all

$i = 0; 
while( /* retrieve data from SQL */ ) { 
  if($i++ % 2 == 0) 
    echo "Odd row\n"; 
  else 
    echo "Even Row\n"; 
} 
this is another alternative
indyboy wrote: just dunno where or how to link the style to the odd and even rows
read the examples in the links provided