Jump to content

Recommended Posts

Hi i'm currently using this to set 1 column of results:

 

<?php
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the starting row to 0 because nothing was found in URL
  $startrow = 0;
//otherwise we take the value from the URL
} else {
  $startrow = (int)$_GET['startrow'];
}

$query = "SELECT id, vName, vDesc, vPrice, vImage FROM vehicles ORDER BY id DESC LIMIT $startrow, 5";
$result = mysql_query($query) or die('Error : ' . mysql_error());

if(mysql_num_rows($result)==0) {
    echo('
<span class="noVehicles"><strong>No Vehicles Listed</strong></span>
');
}

while(list($id, $vName, $vDesc, $vPrice, $vImage) = mysql_fetch_array($result, MYSQL_NUM))
{
?>
<div class="stocklisting">
<div class="stockphoto"><img src="pics/<?php echo $vImage;?>" width="125" /></div>
<div class="stocktext">
<div class="stockname"><?php echo $vName;?></div>
<div class="stockdesc"><?php echo $vDesc;?></div>
<div class="stockprice">£<?php echo $vPrice;?> a month</div>
<div class="stockmore"><a href="specification.php?id=<?php echo $id;?>">view details</a></div>
</div>
</div>
<?php
}

?>

 

 

I now need to change this to a 2 column layout. I have found this script:

 

<?php
$dataTest = array('a','b','c','d','e','f','g');
$table = '<table>';
$counter = 0;
// find total number of items in array. If it's not an even number 
// we need to add 1 so as to avoid breaking the table by 
// omitting the final cell
$total = count($dataTest);
if ($total%2 != 0) {
        $total+=1;
}

// loop through the array
for ($i=0;$i<count($dataTest);$i++) { 
if ($counter%2 == 0) { // first column
     $table .= '<tr><td>' . $dataTest[$i] . '</td>';
} else { // second column        
$table .= '<td>' . $dataTest[$i] . '</td></tr>';
}
$counter++;
} 

// complete table and output results
$table .= '</table>';
echo $table;
?>


 

Does anyone know how to tie the two together?

 

many thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/170239-2-columns/
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.