Page 1 of 1

splitting chexboxs over 3 columns

Posted: Sun Aug 30, 2009 8:03 am
by REwingUK
I'm trying to modify this code so it splits over 3 columns, but at the moment its only over 2. Any help will be much apriciated!

Code: Select all

    $catNode = new sqlNode();
    $catNode->table = "categories";
    $catNode->select = "*";
    // $_SESSION['FatherID'] was cleaned in header.php
    $catNode->where = "where FatherID = {$_SESSION['FatherID']}";   
    $catNode->orderby = "order by Title asc";
    
    if( ($catResult = $mysql->select($catNode)) === false )
        die($mysql->debugPrint());          
        
                $num_checkboxs = mysql_num_rows($catResult);
                
                $count = 0;
                $break = ceil($num_checkboxs/2);
                    
                echo "<td valign='top' class='smallsearch'>";
                echo "<input type='checkbox' name='searchFatherID' value='0' >All Areas<br/>";
                
                while ( $cat = mysql_fetch_assoc($catResult) ){
                    echo "<input type='checkbox' name='searchFatherID[]' value='".$cat['ID']."' ";
                    if($option['Selected'] == "selected")
                        echo "checked='checked'";
                    echo " >";
                    echo $cat['Title'];
                    echo "<br/>";
                    if($count == $break)
                        echo "</td><td valign='top' class='smallsearch'>";
                    $count++;
                }
                
                echo "</td>";

Re: splitting chexboxs over 3 columns

Posted: Sun Aug 30, 2009 11:40 am
by califdon

Code: Select all

$break = ceil($num_checkboxs/3);

Re: splitting chexboxs over 3 columns

Posted: Sun Aug 30, 2009 5:47 pm
by REwingUK
nope, that just puts less in the first column....any other ideas?

Re: splitting chexboxs over 3 columns

Posted: Sun Aug 30, 2009 6:39 pm
by califdon
How do you want them to be listed, across or down, in 3 columns? In other words, do you want:

Code: Select all

   1   2   3
   4   5   6
   7   8   9
or

Code: Select all

   1   4   7
   2   5   8
   3   6   9
?

Re: splitting chexboxs over 3 columns

Posted: Mon Aug 31, 2009 6:45 am
by REwingUK
The 2nd one, so it'll need to do another <td>

Re: splitting chexboxs over 3 columns

Posted: Mon Aug 31, 2009 11:37 am
by REwingUK
anyone have any ideas?

Re: splitting chexboxs over 3 columns

Posted: Mon Aug 31, 2009 1:29 pm
by califdon
REwingUK wrote:The 2nd one, so it'll need to do another <td>
It will have to do a lot more than that. You will probably have to store the values from your query results as an array, temporarily, so you can access it in the order that you need. In constructing an HTML table, the required sequence is: a <tr>...</tr> for each row, within each of which are the <td>...</td>'s for each column within that row. In concept it would be something like this:

Code: Select all

...
$data=Array();
$sql="SELECT xxxx FROM xxxx WHERE xxxx";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
   $data[]=$row[0];
}
$numcolumns=3;
$numrows=ceil(count($data) / $numcolumns);
for($displayrow=1; $displayrow<=$numrows; $displayrow++) {
   echo "<tr>";
   for($i=$displayrow; $i<($displayrow+$numcolumns); $i++) {
      echo "<td>".$data[$i]."</td>";
   }
   echo "</tr>";
}
 
I'm just doing that in my head, it's not code that you can copy and use directly. I don't have the time to test it, but perhaps it will be helpful.