valoukh Posted March 16, 2008 Share Posted March 16, 2008 Hi all. I'm having trouble with the following If Statement, wonder if anyone can help. It's only displaying the first If, i.e. " if ($row['Row'] == "1" )". Not sure what I'm doing wrong. Thanks. <? while($row = mysql_fetch_array($result)) { if ($row['Row'] == "1" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } else { } } echo "</tr><tr>"; while($row = mysql_fetch_array($result)) { if ($row['Row'] == "2" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } else { } } echo "</tr><tr>"; while($row = mysql_fetch_array($result)) { if ($row['Row'] == "3" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } else { } } mysql_close($dbh); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted March 16, 2008 Share Posted March 16, 2008 Why have you got seperate while statements? Move all your ifs into the one while. There is also no need for an else unless your going to do something. Quote Link to comment Share on other sites More sharing options...
valoukh Posted March 16, 2008 Author Share Posted March 16, 2008 Great! That worked; all the brackets were confusing me a bit. I've got a different problem now - table related. I want the records to display on different rows, 1, 2 and 3. So let's say I've got three records for each row, I want to end up with a grid of 3x3. At the moment they're all in one column. Got any ideas? I'm having trouble spotting the problem! Thanks so much for your help. <? while($row = mysql_fetch_array($result)) { if ($row['Row'] == "1" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } echo "</tr><tr>"; if ($row['Row'] == "2" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } echo "</tr><tr>"; if ($row['Row'] == "3" ) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 16, 2008 Share Posted March 16, 2008 I don't see any difference is the output for each if statement. You can combine the if statements into one. <?php while($row = mysql_fetch_array($result)) { if ($row['Row'] == "1" || $row['Row'] == 2 || $row['Row'] == 3) { echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>"; echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>"; echo "</table></td>"; } } ?> Ken Quote Link to comment Share on other sites More sharing options...
valoukh Posted March 16, 2008 Author Share Posted March 16, 2008 Thank Ken. The idea is to have the three types of record on different rows, so I'm trying to get the <td>'s in the right place now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.