ofmyst Posted August 8, 2008 Share Posted August 8, 2008 I have a mysql database with painting info. My php calls the information. However, I only want three images per line, right now it will put as many in the line as I have in the database. I thought the best option was an if statement. I have an ID field set up, they show T01, T02, T03 etc. Is there a way to say If ID = T01 - 03 then, if ID = T04 - 06, etc? Or is there a better way to structure this? Here is what it currently looks like: mysql_select_db("paintings", $con); $result = mysql_query("SELECT * FROM pieces"); while($row = mysql_fetch_array($result)) { echo "<td align='center' width='27%'>"; echo "<font color='white'>" . $row['Image'] . "</font><br>"; echo "<br>"; echo "<font color='white'>" . $row['Link'] . "</font><br>"; echo "<font color='white'>" . $row['Title'] . "</font><br>"; echo "<font color='white'>" . $row['Medium'] . "</font><br>"; echo "<font color='white'>" . $row['Size'] . "</font>"; echo "</td>"; } Thank you very much for any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/118824-solved-php-mysql-problem-with-conditional-if-statement-novice/ Share on other sites More sharing options...
corbin Posted August 9, 2008 Share Posted August 9, 2008 The basic skeleton of it (using tables) is: $max = 16; //random made up number if($max > 0) { echo '<table><tr>'; for($i = 0; $i < $max; ++$i) { if($i+1 % 3 == 0) { echo '<tr>'; if($i+1 != $max) echo '<tr>'; } echo '<td>blah</td>'; } for($i = 3-($max%3); $i > 0; --$i) echo '<td></td>'; echo '</tr></table>'; } Quote Link to comment https://forums.phpfreaks.com/topic/118824-solved-php-mysql-problem-with-conditional-if-statement-novice/#findComment-612185 Share on other sites More sharing options...
ofmyst Posted August 9, 2008 Author Share Posted August 9, 2008 Thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/118824-solved-php-mysql-problem-with-conditional-if-statement-novice/#findComment-612403 Share on other sites More sharing options...
corbin Posted August 9, 2008 Share Posted August 9, 2008 No problem ;p. (Oh, if you need me to explain it I can/will, but the code is fairly straight forward, so I didn't think I would explain it.) Quote Link to comment https://forums.phpfreaks.com/topic/118824-solved-php-mysql-problem-with-conditional-if-statement-novice/#findComment-612425 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.