Help with code - show results in 2 coluns.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alvaro
Forum Newbie
Posts: 12
Joined: Sun Dec 21, 2008 4:12 pm

Help with code - show results in 2 coluns.

Post by alvaro »

hi guys, i m a php beginner and i have a problem thats is.

Code: Select all

<td><? // COMEÇA LISTAR OPCIONAIS
    echo "<fieldset><legend><font color='$Cor1'>Features</font> </legend>";
    $op2 = explode("|",$dados[id_opcionais]);
    $total2 = count($op2);
    //echo $total;
 
        for($i2=0; $i2<$total2; $i2++) { 
        //echo $op[$i]."<br>";
            if($op2[$i2] != ""){
            $opc2 = mysql_fetch_array(mysql_query("SELECT * FROM $tabela7 WHERE id='$op2[$i2]'"));
            //echo "$opc2[nome]";
            
            
            echo "<input name='opcionais[]' type='checkbox' value='$opc2[id]' checked onClick='this.checked=true;'> $opc2[nome] ";
            }
        }
        echo "</fieldset><br>";?></td>
 
this code return me something like this but i need to show this in 2 coluns.

Image

if somebody can help me... thanks in advance.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help with code - show results in 2 coluns.

Post by John Cartwright »

I've never understood why this logic needs to be programmed logically. I find using CSS is much less complicated.

Code: Select all

 
echo "<div style='float; left; width: 49%;'><input name='opcionais[]' type='checkbox' value='". $opc2['id'] ."' checked onClick='this.checked=true;'>". $opc2['nome'] ."</div>";
You will also probably need to clear the floats.

Code: Select all

 
echo "<div style='clear: both;'></div>";
echo "</fieldset><br>";?>
alvaro
Forum Newbie
Posts: 12
Joined: Sun Dec 21, 2008 4:12 pm

Re: Help with code - show results in 2 coluns.

Post by alvaro »

Jcart wrote:I've never understood why this logic needs to be programmed logically. I find using CSS is much less complicated.

Code: Select all

 
echo "<div style='float; left; width: 49%;'><input name='opcionais[]' type='checkbox' value='". $opc2['id'] ."' checked onClick='this.checked=true;'>". $opc2['nome'] ."</div>";
Ur code works too - but i still got just 1 columns.

i think i can use something like this

Code: Select all

<?
$columns=2;
if ($total>0) { 
for ($i = 0; $i < $total; $i++) { 
if (($i%$columns)==0) { 
 
$colspan = $coluns+$coluns+$coluns;
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help with code - show results in 2 coluns.

Post by John Cartwright »

In my example, you may have to adjust the width depending on padding and margins. Usually 1% offset (each column being 49%) is enough, but not always.
alvaro
Forum Newbie
Posts: 12
Joined: Sun Dec 21, 2008 4:12 pm

Re: Help with code - show results in 2 coluns.

Post by alvaro »

Jcart wrote:In my example, you may have to adjust the width depending on padding and margins. Usually 1% offset (each column being 49%) is enough, but not always.

I did like this and now works

Code: Select all

<style type="text/css">
.container
{
  width: 400;
}
 
.div_resultado
{
  float: left;
  width: 200px;
}
 
 
</style>

Code: Select all

echo "<div class='div_resultado' style='float; left; width: 49%;'><input name='opcionais[]' type='checkbox' value='". $opc2['id'] ."' checked onClick='this.checked=true;'>". $opc2['nome'] ."</div>";
            }
        }
        echo "<div style='clear: both;'></div>
Image

Thanks mate, apreciate ur help.
Post Reply