Page 1 of 1

please help put array into columns

Posted: Thu Jun 03, 2010 9:34 am
by rickyspires
please help put array into columns

hello.
the below code puts the most recent row added into a list.
im trying to put the list in to 2 colums
how can i do that?

Code: Select all

<?php
	$shop = array(); 

	$query = "SELECT * FROM form1 WHERE id='$user_id'";
	
	$result = mysql_query($query) or die(mysql_error());
	
	while($row = mysql_fetch_array($result)){
	
	$shop[] = $row['Fname'];
	$shop[] = $row['Sname'];
	$shop[] = $row['description'];
	}


	foreach($shop as $key => $details)	{
	$key++;
	echo $key . ": ". $details . "<br/>";
	}
?>
RESULTS:

1: ricky
2: spires
3: my description



I WOULD LIKE THIS TO BE ECHOED :

result 1 ----------------result 2
result 3 ----------------result 4
result 5 ----------------result 6
result 7 ----------------result 8
result 9 ----------------result 10


thanks
rick

Re: please help put array into columns

Posted: Thu Jun 03, 2010 11:50 am
by markusn00b
Check out this (slightly hacky) code:

Code: Select all

<?php

$array = array(
    'one', 'two', 'three', 'four', 'five'
);

$count = count($array);

for ($i = 0; $i < $count; $i++) {
    
    echo $array[$i];
    if (isset($array[$i + 1])) {
        echo " " . $array[$i + 1];
        $i++;
    }
    echo "\n";    
}