anthony-needs-you Posted August 14, 2009 Share Posted August 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170239-2-columns/ Share on other sites More sharing options...
wildteen88 Posted August 14, 2009 Share Posted August 14, 2009 Please read the follwing FAQ post. Quote Link to comment https://forums.phpfreaks.com/topic/170239-2-columns/#findComment-898076 Share on other sites More sharing options...
anthony-needs-you Posted August 17, 2009 Author Share Posted August 17, 2009 cool cheers Quote Link to comment https://forums.phpfreaks.com/topic/170239-2-columns/#findComment-899950 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.