Jump to content

Dynamic Checkbox List


brassfid

Recommended Posts

Hello all, I found this dynamic checkbox list online.  I have changed it to suit my needs, added some of my own parts but now, after getting past all the terminal errors, it now produces absolutely nothing.  Can I get some help on why there is no echo occurring?  Thanks!

 

<?php

function dynamic_checkbox_table ($sql_str, $col_label, $col_name, $val_checked, $cant_cols_tbl){

        $sql_str = dynamic_checkbox_table("SELECT * FROM Categories");
        $col_label = "catlevel3";
        $col_name = "catlevel3";
        $val_checked="S";
        $cant_cols_tbl=3;
        
        //connect DB and run query
        $db="TB";
        $db_user="";
        $pass="";
        $host="localhost";
        @mysql_connect($host,$db_user,$pass);
        @mysql_select_db($db) or die ("cannot connect to DB");
        $q_resultado = mysql_query($sql_str);
        mysql_close();
        if (mysql_num_rows($q_resultado)==0) exit("no rows returned");
        
        $next_row = mysql_fetch_array($q_resultado); //fetch first row
        
        $output = "<table  border=\"1\">\n"; //open table tag
        do {
                $output .= "<tr>\n"; //open row tag
                for ($i=1 ; $i <= $cant_cols_tbl ; $i++ ){ //loops as many times as $cant_cols_tbl
                        $row=$next_row; 
                        $output .= "<td>"; //open TD tag
                        $output .= (!$row) ? "" : '<input type="checkbox" name="'.$row[$col_name].'" value="'.$val_checked.'" />'.$row[$col_label]; 
                        echo (!$row) ? "" : '<input type="checkbox" name="'.$row[$col_name].'" value="'.$row[$val_checked].'" />'.$row[$col_label]; 
                        $next_row = mysql_fetch_array($q_resultado); //retrieve next row
                        $output .= "</td>\n"; //close TD
                } //close for loop
                $output .= "</tr>\n"; //close row
        } while ($next_row); //close do-while (and checks if there's another row)
        $output .= "</table>\n"; //close table
        return $output; 
}

?>

Link to comment
https://forums.phpfreaks.com/topic/226059-dynamic-checkbox-list/
Share on other sites

Are PHP errors turned on?

 

Did you check the source?  Is it outputting HTML but you just can't see it?

 

The function returns an output, it doesn't echo it automatically.  When you use the function, are you using it like this?

 

echo dynamic_checkbox_table(...);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.