Jump to content

Display data in two columns rather than one


Corinthian

Recommended Posts

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. :)

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";

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";
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.