Dynamic Checkboxes
Posted: Fri Jan 28, 2011 12:29 am
Alright, I built this script off of something that I found online. I spent quite some time working past all the errors, but now I have absolutely nothing populating. It is just blank. Can anyone point out the issue? Thanks!
Code: Select all
<?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;
}
?>