Jump to content

dennismonsewicz

Members
  • Posts

    1,136
  • Joined

  • Last visited

Everything posted by dennismonsewicz

  1. is there anyway to use that code to not display the first two records? while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= $k . " "; } } echo $column;
  2. code i am working with: <?php /*ini_set ("display_errors", "1"); error_reporting(E_ALL);*/ include "includes/sql.php"; $id = 24; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'")or die(mysql_error()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $checkbox_results = mysql_fetch_object($checkbox_qry); $field = mysql_num_fields($checkbox_qry); for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $title .= $names . "<br />"; /*$nobreak .= '"' . $names . '",';*/ } echo $title; ?> I am wanting to set the $names field into an array where the individual array values are the names of the individual SQL table column names... anyway of doing this?
  3. wow its amazing the things you learn on this forum! LOL! thanks it works! Here is the code for those who want to know how it works: <?php /*ini_set ("display_errors", "1"); error_reporting(E_ALL);*/ include "includes/sql.php"; $id = 24; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'")or die(mysql_error()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $field = mysql_num_fields($checkbox_qry); for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $title .= $names . "<br />"; } echo $title; ?>
  4. the $title var Its showing the id and project field (which are the first two columns in the DB table)... I am wanting to not show these in the list
  5. well the problem is, is that there is no array here so array_slice() does not work...
  6. Code: <?php /*ini_set ("display_errors", "1"); error_reporting(E_ALL);*/ include "includes/sql.php"; $id = 24; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'")or die(mysql_error()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $field = mysql_num_fields($checkbox_qry); for($i = 0; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $title .= trim($names) . "<br />"; } echo $title; ?> How would I delete the first two entries in the array?
  7. ok I now have all of the field names displaying, but I need to delete the first two out of the list how would I do this? updated code: <?php /*ini_set ("display_errors", "1"); error_reporting(E_ALL);*/ include "includes/sql.php"; $id = 24; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'")or die(mysql_error()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $field = mysql_num_fields($checkbox_qry); for($i = 0; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $title .= trim($names) . "<br />"; } echo $title; ?>
  8. I found some errors in the code I was testing Updated Code: <?php include "includes/sql.php"; $id = "24"; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'") or die(mysql_error()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $results_qry = mysql_fetch_array($checkbox_qry); foreach($results_qry[] as $key => $val) { echo $key . "=" $val; }
  9. Here is something I am playing with: <?php include "includes/sql.php"; $query = mysql_query("SELECT * FROM added_projects WHERE id = '$id'") or die(mysql_query()); $results = mysql_fetch_object($query); $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $results_qry = mysql_fetch_array($checkbox_qry); foreach($results_qry[] as $key => $val) { echo $key . "=" $val; } ?> I know how to do the suggestion by Maq... thanks though!
  10. I reckon I am just trying to come up with a easier solution than having to write a million if statements for this... For example: if($results->pm1 == 1) { $checked = "checked" } pm1 is a DB column name
  11. I am wanting to loop through a SQL DB and loop through the rows and where ever there is a 1 display something. Whats the best way of doing that? The DB table column names correspond to checkboxes... anyway to grab these and spit them out?
  12. problem solved! Updated Code for anyone wanting to know how this works: foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key . ","; $data_value .= "'" . $val . "'" . ","; } $trimmed_name = trim($data_name, ','); $trimmed_value = trim($data_value, ','); $qry = mysql_query("INSERT INTO fake ($trimmed_name) VALUES ($trimmed_value)")or die(mysql_error());
  13. I was doing some debugging and found out what my problem was Code: <?php foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key . ","; $data_value .= $val . ","; } $trimmed_name = trim($data_name, ','); $trimmed_value = trim($data_value, ','); $qry = "INSERT INTO fake ($trimmed_name) VALUES ('$trimmed_value')"; echo $qry; /*$result = mysql_query($qry) or die(mysql_error());*/ ?> Is spitting out: INSERT INTO fake (pm1,designer1) VALUES ('1,1') So its not treating the ones as individual answers but as one... anyway to fix this?
  14. The DB is setup with id being auto incremented and the primary key then the column names are the same names that match the checkbox names in the array. Each table cell holds a 0 until the information is passed to the DB that changes the 0 to a 1, essentially turning it "on". sasa I tried your code and it only uses the last value in the checkbox array, it deletes the rest.
  15. the code you provided worked! Here's a new problem lol foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key . ","; $data_value .= $val . ","; } $trimmed_name = trim($data_name, ','); $trimmed_value = trim($data_value, ','); $qry = mysql_query("INSERT INTO fake ($trimmed_name) VALUES ('$trimmed_value')") or die(mysql_error()); I am receiving the following mysql error: Column count doesn't match value count at row 1 any ideas?
  16. now its deleting everything in the string accept for the last string For Example: echo '<form action="foreach.php?action=results" method="post">'; echo '<div><input type="checkbox" name="checkboxes[pm1]" class="checkbox" id="pm1" value="1" /> <label for="pm1">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer1]" class="checkbox" id="designer1" value="1" /> <label for="designer1">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm2]" class="checkbox" id="pm2" value="1" /> <label for="pm2">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[writer]" class="checkbox" id="writer" value="1" /> <label for="writer">Writer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm3]" class="checkbox" id="pm3" value="1" /> <label for="pm3">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer2]" class="checkbox" id="designer2" value="1" /> <label for="designer2">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm4]" class="checkbox" id="pm4" value="1" /> <label for="pm4">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[christine]" class="checkbox" id="christine" value="1" /> <label for="christine">Christine</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm5]" class="checkbox" id="pm5" value="1" /> <label for="pm5">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer3]" class="checkbox" id="designer3" value="1" /> <label for="designer3">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm6]" class="checkbox" id="pm6" value="1" /> <label for="pm6">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[julie]" class="checkbox" id="julie" value="1" /> <label for="julie">Julie</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm7]" class="checkbox" id="pm7" value="1" /> <label for="pm7">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer4]" class="checkbox" id="designer4" value="1" /> <label for="designer4">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm8]" class="checkbox" id="pm8" value="1" /> <label for="pm8">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[proofreading]" class="checkbox" id="proofreading" value="1" /> <label for="proofreading">Proofreading</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm9]" class="checkbox" id="pm9" value="1" /> <label for="pm9">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[layne]" class="checkbox" id="layne" value="1" /> <label for="layne">Layne</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm10]" class="checkbox" id="pm10" value="1" /> <label for="pm10">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[programming]" class="checkbox" id="programming" value="1" /> <label for="programming">Programming</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm11]" class="checkbox" id="pm11" value="1" /> <label for="pm11">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[testing]" class="checkbox" id="testing" value="1" /> <label for="testing">Testing</label></div>'; echo '<input type="submit" value="Submit" />'; echo '</form>'; If you run the above code then select two or more boxes: foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value = $val; } echo trim($data_name, ','); It will delete everyone of the answers in the checkboxes array except for the last one checked. So if you check box1, box2, box3 the foreach code will spit out only box3
  17. Still the same problem updated code: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include "includes/sql.php"; $action = $_GET['action']; switch($action) { case "foreach": echo '<form action="foreach.php?action=results" method="post">'; echo '<div><input type="checkbox" name="checkboxes[pm1]" class="checkbox" id="pm1" value="1" /> <label for="pm1">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer1]" class="checkbox" id="designer1" value="1" /> <label for="designer1">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm2]" class="checkbox" id="pm2" value="1" /> <label for="pm2">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[writer]" class="checkbox" id="writer" value="1" /> <label for="writer">Writer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm3]" class="checkbox" id="pm3" value="1" /> <label for="pm3">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer2]" class="checkbox" id="designer2" value="1" /> <label for="designer2">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm4]" class="checkbox" id="pm4" value="1" /> <label for="pm4">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[christine]" class="checkbox" id="christine" value="1" /> <label for="christine">Christine</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm5]" class="checkbox" id="pm5" value="1" /> <label for="pm5">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer3]" class="checkbox" id="designer3" value="1" /> <label for="designer3">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm6]" class="checkbox" id="pm6" value="1" /> <label for="pm6">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[julie]" class="checkbox" id="julie" value="1" /> <label for="julie">Julie</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm7]" class="checkbox" id="pm7" value="1" /> <label for="pm7">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer4]" class="checkbox" id="designer4" value="1" /> <label for="designer4">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm8]" class="checkbox" id="pm8" value="1" /> <label for="pm8">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[proofreading]" class="checkbox" id="proofreading" value="1" /> <label for="proofreading">Proofreading</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm9]" class="checkbox" id="pm9" value="1" /> <label for="pm9">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[layne]" class="checkbox" id="layne" value="1" /> <label for="layne">Layne</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm10]" class="checkbox" id="pm10" value="1" /> <label for="pm10">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[programming]" class="checkbox" id="programming" value="1" /> <label for="programming">Programming</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm11]" class="checkbox" id="pm11" value="1" /> <label for="pm11">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[testing]" class="checkbox" id="testing" value="1" /> <label for="testing">Testing</label></div>'; echo '<input type="submit" value="Submit" />'; echo '</form>'; break; case "results": foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value = $val; $pos = strrpos($data_name, ","); echo substr_replace($data_name, '',$pos, 1); } /*$qry = mysql_query("INSERT INTO fake (" . $data_name . ") VALUES ('$data_value')") or die(mysql_error());*/ break; } ?>
  18. ok so here is the latest problem i am having updated code: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include "includes/sql.php"; $action = $_GET['action']; switch($action) { case "foreach": echo '<form action="foreach.php?action=results" method="post">'; echo '<div><input type="checkbox" name="checkboxes[pm1]" class="checkbox" id="pm1" value="1" /> <label for="pm1">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer1]" class="checkbox" id="designer1" value="1" /> <label for="designer1">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm2]" class="checkbox" id="pm2" value="1" /> <label for="pm2">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[writer]" class="checkbox" id="writer" value="1" /> <label for="writer">Writer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm3]" class="checkbox" id="pm3" value="1" /> <label for="pm3">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer2]" class="checkbox" id="designer2" value="1" /> <label for="designer2">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm4]" class="checkbox" id="pm4" value="1" /> <label for="pm4">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[christine]" class="checkbox" id="christine" value="1" /> <label for="christine">Christine</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm5]" class="checkbox" id="pm5" value="1" /> <label for="pm5">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer3]" class="checkbox" id="designer3" value="1" /> <label for="designer3">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm6]" class="checkbox" id="pm6" value="1" /> <label for="pm6">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[julie]" class="checkbox" id="julie" value="1" /> <label for="julie">Julie</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm7]" class="checkbox" id="pm7" value="1" /> <label for="pm7">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer4]" class="checkbox" id="designer4" value="1" /> <label for="designer4">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm8]" class="checkbox" id="pm8" value="1" /> <label for="pm8">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[proofreading]" class="checkbox" id="proofreading" value="1" /> <label for="proofreading">Proofreading</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm9]" class="checkbox" id="pm9" value="1" /> <label for="pm9">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[layne]" class="checkbox" id="layne" value="1" /> <label for="layne">Layne</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm10]" class="checkbox" id="pm10" value="1" /> <label for="pm10">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[programming]" class="checkbox" id="programming" value="1" /> <label for="programming">Programming</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm11]" class="checkbox" id="pm11" value="1" /> <label for="pm11">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[testing]" class="checkbox" id="testing" value="1" /> <label for="testing">Testing</label></div>'; echo '<input type="submit" value="Submit" />'; echo '</form>'; break; case "results": foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value = $val; $data_name = rtrim($data_name, ','); echo $data_name; } /*$qry = mysql_query("INSERT INTO fake (" . $data_name . ") VALUES ('$data_value')") or die(mysql_error());*/ break; } ?> the problem is, is that your code is treating each $key as an individual answer and so it stripping each comma occurance. Any other ideas?
  19. the page is now just white Here is the updated code: foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value .= $val; $data_name = substr_replace($data_name, "", strrchr($data_name, ",")); echo $data_name; }
  20. Here's the code: foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value .= $val; $length = strlen($data_name); $fname = trim(substr($data_name,$length-1,$length)); $fname = str_replace($fname, " ", $data_name); echo $fname; } It is taking out every single one of the commas from the $data_name var and I need it to only take out the last comma.. Any ideas?
  21. the problem i am having is the if statement is being hit as well as the data being processed in the foreach statement. Here is the updated code: <?php include "includes/sql.php"; $action = $_GET['action']; switch($action) { case "foreach": echo '<form action="foreach.php?action=results" method="post">'; echo '<div><input type="checkbox" name="checkboxes[pm1]" class="checkbox" id="pm1" value="1" /> <label for="pm1">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer1]" class="checkbox" id="designer1" value="1" /> <label for="designer1">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm2]" class="checkbox" id="pm2" value="1" /> <label for="pm2">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[writer]" class="checkbox" id="writer" value="1" /> <label for="writer">Writer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm3]" class="checkbox" id="pm3" value="1" /> <label for="pm3">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer2]" class="checkbox" id="designer2" value="1" /> <label for="designer2">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm4]" class="checkbox" id="pm4" value="1" /> <label for="pm4">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[christine]" class="checkbox" id="christine" value="1" /> <label for="christine">Christine</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm5]" class="checkbox" id="pm5" value="1" /> <label for="pm5">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer3]" class="checkbox" id="designer3" value="1" /> <label for="designer3">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm6]" class="checkbox" id="pm6" value="1" /> <label for="pm6">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[julie]" class="checkbox" id="julie" value="1" /> <label for="julie">Julie</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm7]" class="checkbox" id="pm7" value="1" /> <label for="pm7">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[designer4]" class="checkbox" id="designer4" value="1" /> <label for="designer4">Designer</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm8]" class="checkbox" id="pm8" value="1" /> <label for="pm8">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[proofreading]" class="checkbox" id="proofreading" value="1" /> <label for="proofreading">Proofreading</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm9]" class="checkbox" id="pm9" value="1" /> <label for="pm9">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[layne]" class="checkbox" id="layne" value="1" /> <label for="layne">Layne</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm10]" class="checkbox" id="pm10" value="1" /> <label for="pm10">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[programming]" class="checkbox" id="programming" value="1" /> <label for="programming">Programming</label></div>'; echo '<div><input type="checkbox" name="checkboxes[pm11]" class="checkbox" id="pm11" value="1" /> <label for="pm11">PM</label></div>'; echo '<div><input type="checkbox" name="checkboxes[testing]" class="checkbox" id="testing" value="1" /> <label for="testing">Testing</label></div>'; echo '<input type="submit" value="Submit" />'; echo '</form>'; break; case "results": $i = 0; foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key; $data_value .= $val; echo $data_name; if( $i != sizeof( $_POST[ "checkboxes" ] ) - 1 ) { $data_name .= ","; $data_value .= ","; } $i++; } $qry = mysql_query("INSERT INTO fake (" . $data_name . ") VALUES ('$data_value')") or die(mysql_error()); break; } ?> When I run the code and spit out the results, lets say I select the first two checkboxes and then click submit I receive this: pm1pm1,designer1 If I select three checkboxes: pm1pm1,designer1pm1,designer1,pm2 Any help?
  22. ok so i have it working with this code (but with a small problem) $val=''; foreach($_POST['checkboxes'] as $key=>$val) { $data_name = $key . ","; $data_value = $val . ","; } $qry = mysql_query("INSERT INTO fake ($data_name) VALUES ('$data_value')") or die(mysql_error()); The problem is, is that there is a comma that is created at the end of the $data_name var and its exploding the SQL statement. How can I truncate the last comma?
  23. both is fine, I am only printing them out to show the results
×
×
  • 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.