splitting chexboxs over 3 columns

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
REwingUK
Forum Commoner
Posts: 26
Joined: Wed Jul 29, 2009 8:46 pm

splitting chexboxs over 3 columns

Post 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>";
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: splitting chexboxs over 3 columns

Post by califdon »

Code: Select all

$break = ceil($num_checkboxs/3);
REwingUK
Forum Commoner
Posts: 26
Joined: Wed Jul 29, 2009 8:46 pm

Re: splitting chexboxs over 3 columns

Post by REwingUK »

nope, that just puts less in the first column....any other ideas?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: splitting chexboxs over 3 columns

Post 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
?
REwingUK
Forum Commoner
Posts: 26
Joined: Wed Jul 29, 2009 8:46 pm

Re: splitting chexboxs over 3 columns

Post by REwingUK »

The 2nd one, so it'll need to do another <td>
REwingUK
Forum Commoner
Posts: 26
Joined: Wed Jul 29, 2009 8:46 pm

Re: splitting chexboxs over 3 columns

Post by REwingUK »

anyone have any ideas?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: splitting chexboxs over 3 columns

Post 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.
Post Reply