PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
indyboy
Forum Newbie
Posts: 6 Joined: Mon May 10, 2010 4:36 am
Post
by indyboy » Mon May 10, 2010 4:52 am
Hey all
ive been trying to figure this out for a while now and my brains gone into meltdown.
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
Cheers
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Mon May 10, 2010 8:25 am
post the code that you have so far and will move from there
indyboy
Forum Newbie
Posts: 6 Joined: Mon May 10, 2010 4:36 am
Post
by indyboy » Mon May 10, 2010 8:44 am
im not great at explaining so heres a picture of the layout im looking for
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
indyboy
Forum Newbie
Posts: 6 Joined: Mon May 10, 2010 4:36 am
Post
by indyboy » Mon May 10, 2010 9:04 am
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
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Mon May 10, 2010 9:53 am
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