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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.