rdub Posted October 8, 2008 Share Posted October 8, 2008 I'd like these results to display in two columns: <? //select the table $result = mysql_query("select * from properties where Sale like '%yes%'"); //grab all the content while($row=mysql_fetch_assoc($result)) { ?> <table width="200" align="center" class="sample"> <tr> <td width="533"><table width="200" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="200" align="center" valign="top"><img src='<? echo $row['Image']; ?>' alt="table" height="140" width="200" /><br> <span class="style1a">'<? echo $row['hi_lite']; ?>'</span></td> </tr> <tr> <td width="200" align="center" valign="middle" class="style3"><span class="style1b"><? echo $row['Description']; ?></span></td> </tr> <tr> <td width="200" align="center" valign="middle" class="style3"> <? if( $row['Web'] != "") { echo '<a href="'.$row['Web'].'" target="_self">click here</a>'; } ?> </td> </tr> </table></td> </tr> </table> <? // End While statement } // Close database connection. //mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/ Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 1. please use code tags. 2. are there any errors? 3. if not, what is the current output? Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660393 Share on other sites More sharing options...
rdub Posted October 9, 2008 Author Share Posted October 9, 2008 No errors. All prints within a table as desired. However, it now displays each record one after the other but in one column. I'd like to break the display into 2 columns. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660505 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 You should start your table above the while loop and end it after the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660550 Share on other sites More sharing options...
rdub Posted October 9, 2008 Author Share Posted October 9, 2008 To be more specific, I'd like the records to display in at least 2 columns. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660609 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Can't you just put tags around the sql variables where you want columns? Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660616 Share on other sites More sharing options...
AndyB Posted October 9, 2008 Share Posted October 9, 2008 http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660619 Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Maybe this is closer to what you want...I removed a bunch of formatting as it was getting in my way, you can add it back as you need. In your while loop you started and ended your table, so there were many tables created. Then you had a table within a table. I removed one of them. Now you have 3 columns. 1) $row['Image'] 2) $row['Description'] 3) If there is a link print it, if not print a space (td's don't like to be empty, so put a space in there) oh, and always use full php tags, not <? short tags. <?php //select the table $result = mysql_query("select * from properties where Sale like '%yes%'"); echo '<table width="200" align="center" class="sample">'; //grab all the content while($row=mysql_fetch_assoc($result)) { ?> <tr> <td><img src="<?php echo $row['Image']; ?>" /><br><span><?php echo $row['hi_lite']; ?></span></td> <td><span><?php echo $row['Description']; ?></span></td> <td width="200" align="center" valign="middle" class="style3"> <?php if( $row['Web'] != "") { echo '<a href="'.$row['Web'].'" target="_self">click here</a>'; } else { echo " "; } ?> </td> </tr> <?php } // End While statement echo '</table>'; // Close database connection. //mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660634 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 I think your main problem was that you had a table in the while loop so you were just created a bunch of tables. Also, like cronix said, when you have an empty column do it like this . Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660638 Share on other sites More sharing options...
rdub Posted October 9, 2008 Author Share Posted October 9, 2008 I apologize as I haven't made myself clear Here is what I have now record 1 record 2 record 3 Here is what I need record record record record record record Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660884 Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 You can use my above example to accomplish what you need. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660952 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Yes what you have is: record 1 record 2 record 3 What you need is: record record record record record record See this difference, it's basic HTML? Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660955 Share on other sites More sharing options...
rdub Posted October 9, 2008 Author Share Posted October 9, 2008 Obviously I'm not being clear enough. As you can see from the code, the query results "print" within a table, one record below another. If there are 10 records in the database table then they print one below the other until all 10 are seen. I would like for the table containing the results to "print/echo" in two to three columns rather than one below the other. With two columns the same 10 records would print two across and 5 down. I apologize if I'm not explaining this correctly. Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-661114 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Ah ok sorry. You should get the number of results and when you reach over half start a new column. I don't know if it's the best way to do it but I should work. $half = mysql_num_rows($result)/2; while(...){ . . if($t > $half) { echo ""; } $t++; } Quote Link to comment https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-661123 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.