Corinthian Posted July 4, 2011 Share Posted July 4, 2011 Hi all, I barely know a thing about PHP so far, but I need to make some small changes to some code I have, and my coder has vanished leaving me really screwed. I need to change this page so that the showroom logos are displayed in two columns rather than one. The page is http://www.carsindoha.com/showrooms.php <?php $title = 'Car Showroom in Doha'; include_once "includes/header.php"; ?> <h1>Car Showrooms in Doha</h1> <p> </p> <p>Below is a list of all the car showrooms in Doha. Clicking on any of their logos to see a full list of all cars we currently list from that particular showroom.</p> <?php include_once "includes/main.php"; ?> <? $showroom_query = @mysql_query('SELECT * FROM `showroom` ORDER BY `showroom` ASC;'); if(@mysql_num_rows($showroom_query) > 0) { while($showroom = @mysql_fetch_assoc($showroom_query)) { ?> </p> <div> <a href="advanced_search.php?showroom=<? echo $showroom['showroom_id']; ?>"><img width="243" height="42" src="images/showrooms/showroom_<? echo $showroom['showroom_id']; ?>_1.gif"><br /> <? echo $showroom['showroom']; ?></a> </div><br> <? } } else { echo 'No results.'; } ?> <?php include_once "includes/footer.php"; ?> If anyone can help at all, it would me eternally grateful. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/ Share on other sites More sharing options...
EdwinPaul Posted July 4, 2011 Share Posted July 4, 2011 Try this: $showroom_query = mysql_query('SELECT * FROM `showroom` ORDER BY `showroom` ASC;'); if(mysql_num_rows($showroom_query) > 0) { $columns=2; $counter=1; while($showroom = mysql_fetch_array($showroom_query)) { echo '<a href="advanced_search.php?showroom='.$showroom['showroom_id'].'"><img width="243" height="42" src="images/showrooms/showroom_'.$showroom['showroom_id']'._1.gif" alt="">'.$showroom['showroom'].'</a>'; $counter++; if($counter>$columns) { echo '<br/>'; $counter=1; } } }else{ echo 'No results.'; } include_once "includes/footer.php"; Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238222 Share on other sites More sharing options...
Corinthian Posted July 4, 2011 Author Share Posted July 4, 2011 Hi EdwinPaul, Thank you for your help. I've tried the code you suggested, but it doesn't seem to be working. As far as I know I've correctly copied it. The only thing I've done different is keep the include in a seperate tag. Could you have another check and see where it's going wrong? Thank you again. <?php $title = 'Car Showroom in Doha'; include_once "includes/header.php"; ?> <h1>Car Showrooms in Doha</h1> <p> </p> <p>Below is a list of all the car showrooms in Doha. Clicking on any of their logos to see a full list of all cars we currently list from that particular showroom.</p> <?php include_once "includes/main.php"; ?> <? $showroom_query = mysql_query('SELECT * FROM `showroom` ORDER BY `showroom` ASC;'); if(mysql_num_rows($showroom_query) > 0) { $columns=2; $counter=1; while($showroom = mysql_fetch_array($showroom_query)) { echo '<a href="advanced_search.php?showroom='.$showroom['showroom_id'].'"><img width="243" height="42" src="images/showrooms/showroom_'.$showroom['showroom_id']'._1.gif" alt="">'.$showroom['showroom'].'</a>'; $counter++; if($counter>$columns) { echo '<br/>'; $counter=1; } } }else{ echo 'No results.'; } ?> <?php include_once "includes/footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238239 Share on other sites More sharing options...
Corinthian Posted July 4, 2011 Author Share Posted July 4, 2011 Please, if anyone can help me solve this, I'm really desperate. Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238279 Share on other sites More sharing options...
EdwinPaul Posted July 4, 2011 Share Posted July 4, 2011 I checked it again, but I don't see what can be wrong. What is (not) happening? Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238282 Share on other sites More sharing options...
EdwinPaul Posted July 4, 2011 Share Posted July 4, 2011 On your site I can see that it is not working. I can also see in the source that you did not copy the part I was giving you. Another consideration: Is the space where you want the picture + text wide enough for 2? I don't think so. Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238290 Share on other sites More sharing options...
EdwinPaul Posted July 4, 2011 Share Posted July 4, 2011 If you remove the <div> </div> <p> and </p> from within your while-loop, things should go better. But really re-calculate the space ! Quote Link to comment https://forums.phpfreaks.com/topic/241059-display-data-in-two-columns-rather-than-one/#findComment-1238292 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.