Split result into 2 columns tableless

I write this as remainder about splitting sql results table less cause sometime i forget how to do it, i’m not a php programmer so this is what i can think of to solve my problem to split mysql result into 2 columns I use modulo to achieve it and output results in div,ul,li instead of table, tr,td,

2col-div


formating the ouput with css is the key

<style>
#colOne ul{
float: left;
width: 220px;
margin: 0px; border-bottom:1px dotted #999;border-right:1px dotted #999;
}

#colOne ul li{
list-style:none;
}

#colOne ul li a{
font-size: 11px;
color: #636363;
height: 54px !important;
height: 50px;
margin:0px 0px 0px 0px;
padding:10px 10px 10px 0px;
display:block;
list-style:none;
text-decoration: none;
}

#colOne ul li a:hover{
color:#000000;
background-color:#F8F8F8;
text-decoration:none;
}

#colTwo ul{
float: right;
width: 49%;
margin: 0px;border-bottom:1px dotted #999;
}

#colTwo ul li{
list-style:none;
}

#colTwo ul li a{
font-size: 11px;
color: #636363;
height: 54px !important;
height: 50px;
margin:0px 0px 0px 0px;
padding:10px 10px 10px 0px;
display:block;
list-style:none;text-decoration: none;
}

#colTwo ul li a:hover{
color:#000000;
background-color:#F8F8F8;
text-decoration:none;
}

#colTwo img, #colOne img{
background-color: #ffffff;
border: 1px solid red;
margin: 0px 12px 8px 0px;
float: left;
}
#colTwo h1, #colOne h1{
color:orange;font-size:8pt;font-weight:bold;margin:0;padding:0;
}
#colTwo h6, #colOne h6{
color:#FF3300;font-size:8pt;font-weight:normal;margin:0;padding:0;
}
#colTwo{padding-left:34px;}
</style>

And the php code goes like this

<div style=”width: 560px; font-family: sans-serif;”>
<?php

//here i use a bunch of strings seperate by pipe sign for each section
//of course string could be your sql query results

$str = ‘Villa Teresa,US$120,Villa Teresa Bali is situated on the beach of Canggu Village|Sienna Villa,US$148,Red Heart Special for beautiful 3 bedroom villas. Located at Seminyak  South Bali|COMO Shambhala,US$158,a private estate located amidst the serenity of Bali\’s stunning landscape|Villa Teresa,US$120,Villa Teresa Bali is situated on the beach of Canggu Village|Sienna Villa,US$148,Red Heart Special for beautiful 3 bedroom villas. Located at Seminyak South Bali|COMO Shambhala,US$158,a private estate located amidst the serenity of Bali\’s stunning landscape’;

$expOne = explode(‘|’,$str );
foreach ($expOne as $valOne){
$expTwo=explode(‘,’,$valOne);
$title[] = $expTwo[0];
$rate[] = $expTwo[1];
$introtext[] = $expTwo[2];
}

$n = count( $expOne );
$i = 0;
//iteration for total part
for ($i=0; $i < $n; $i++){
?>

And the modulo in action

<div id=”<?php echo $i % 2?’colTwo’:’colOne’; ?>”>
<ul>
<li> <a href=”#”><h1> <php echo $title[$i];> </h1>
<h6>< ? echo $rate[$i];?></h6>
<? echo $introtext[$i];?></a>
</li>
</ul>
</div>
<?}?>
</div>

Leave a Reply

Your email address will not be published.