brassfid Posted January 29, 2011 Share Posted January 29, 2011 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226059-dynamic-checkbox-list/ Share on other sites More sharing options...
l4nc3r Posted January 29, 2011 Share Posted January 29, 2011 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(...); Quote Link to comment https://forums.phpfreaks.com/topic/226059-dynamic-checkbox-list/#findComment-1166996 Share on other sites More sharing options...
brassfid Posted January 29, 2011 Author Share Posted January 29, 2011 Ahh, there is nothing being pushed out currently. I am using the script in a php document and then on the page itself I use: <?php include('/wp-content/aroma.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/226059-dynamic-checkbox-list/#findComment-1167004 Share on other sites More sharing options...
l4nc3r Posted January 29, 2011 Share Posted January 29, 2011 Including the file isn't enough--you have to call the function and echo out what it returns. Quote Link to comment https://forums.phpfreaks.com/topic/226059-dynamic-checkbox-list/#findComment-1167017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.