read the second last post, the one feyd made, looks to me that it would be very helpful...
by the looks of it, it gets the info from the database and displays it in rows like you needed. alittle bit of modification and it could be suited to your cause...
Making Nice Tables
Moderator: General Moderators
I'd like to point out you could have used the modulus, that way you dont have to reset the [$rownum] variable every iteration, and you can have a variable representing the total amount of rows looped.
Also a couple mistakes you made:
'1' on line three should really probably be an integer instead of a string
Also a couple mistakes you made:
'1' on line three should really probably be an integer instead of a string
mickd wrote:something like this should do it (prolly needs tweaking) and your elseif:
, should be $rownum == 2Code: Select all
} elseif($rownum = 2) {
Other than that it should do exactly what the OP was asking.
Code: Select all
echo '<table>'; $rownum = 1; while($row = mysql_fetch_assoc($result)) { if($rownum == '1') { echo '<tr> <td>' . $row['name'] . ' </td>'; $rownum++; } elseif($rownum = 2) { echo ' <td>' . $row['name'] . ' </td> </tr>'; $rownum = 1; } } if((mysql_num_rows($result) % 2) == 1) { echo '</tr>'; } echo '</table>';
yeah i was going to but it lead to some confusion while i was writing it so i just left it out 
because of that i couldnt think of a way to tell the difference between row 1 and row 2
o wait, if i used 3 % 1 and 3 % 2 instead
Code: Select all
2%1 == 0
2%2 == 0o wait, if i used 3 % 1 and 3 % 2 instead
oops} elseif($rownum = 2) {
, should be $rownum == 2
oops, just too used to writing '' even if its bad practise :S'1' on line three should really probably be an integer instead of a string
Code: Select all
if ( $rownum % 2 == 0 )mickd wrote:yeah i was going to but it lead to some confusion while i was writing it so i just left it out
Code: Select all
2%1 == 0 2%2 == 0
Problem Solved
Well, thanks for all of the input, I guess the best way to learn things around here is to get all the programmers on this forum to start brainstorming on your topic. I now have my issue solved thanks to DevNetwork!
Here is my working code I put together from all of your brainstorming:
Here is my working code I put together from all of your brainstorming:
Code: Select all
<?php
$rownum = "1";
$color1 = "#F5F5F5";
$color2 = "#E9E9E9";
$rowcount = "0";
$result = mysql_query("SELECT * FROM specials ORDER BY sortorder ASC");
while($row = mysql_fetch_assoc($result)) {
$rowcolor = ($rowcount % "2") ? $color1 : $color2;
if($rownum == "1") {
?>
<tr>
<td bgcolor="<?php echo $rowcolor; ?>" align="center" valign="top" width="188">
<font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
<br><br>
<a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
<font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
<br><br>
<font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
</td>
<?php
$rownum++;
} elseif($rownum == "2") {
?>
<td bgcolor="<?php echo $rowcolor; ?>" align="center" valign="top" width="187">
<font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
<br><br>
<a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
<font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
<br><br>
<font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?php
$rownum = "1";
$rowcount++;
}
}
if((mysql_num_rows($result) % "2") == "1") {
echo "</tr>\n";
}
?>