pixeltrace Posted February 24, 2007 Share Posted February 24, 2007 guys, i need help, i have a form and it has a check box permanent contract parttime what i want to happen is if the current value in my database is permanent i want the checkbox of permanent to be checked. i have a script for it but its not working hope you could help me with this. below is my code for this problem <input type="checkbox" name="jtype" value="<? if($_GET['j_type']== 'permanent')print 'checked'; ?>"> Permanent <input type="checkbox" name="jtype" value="<? if ($_GET['j_type'] == 'contract')print 'checked'; ?>"> Contract <input type="checkbox" name="jtype" value="<? if ($_GET['j_type'] == 'part time')print 'checked'; ?>"> Part Time need help on this please thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/ Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Try $_REQUEST rather then $_GET Shouldn't that be: <input type="checkbox" name="j_type" value="<? if($_REQUEST['j_type']== 'permanent') { print 'checked' ; }?>"> Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192958 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Also your saying your getting this from a database and not from a form that was submitted? If that is the case the Request and Get have no clue what your telling it to look for. You need to setup a varible for each checkbox and its value for it to pass thru with changes. $j_type = $row[x] ; if ($j_type == 1) { $j_type_ck = "checked" ; } else { $j_type = 0 ; $j_type_ck = "" ; } Then for the checkbox <input type="checkbox" name="j_type" value="<?php echo $j_type ; ?>" <?php echo $j_type_ck ; ?>> Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192969 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 i cannot echo the value since this page is an updateform page. i just need the current value from the database so the user who will update will know what is the current j_type that was checked. this is the code for my query and the current code that i have for my checkboxes <? include 'db_connect.php'; $query = mysql_query("SELECT staff_created, j_position, c_name, cperson, specialization, level, industry, c_description, j_requirements, j_responsibilities, j_type, salary, location, DAY(date_posted), MONTH(date_posted), YEAR(date_posted), DAY(date_closed), MONTH(date_closed), YEAR(date_closed), j_status, remarks FROM job_ads WHERE jobid= '$jobid'") or die(mysql_error()); $row = mysql_fetch_array( $query ); $staff_created = $row["staff_created"]; $j_position = $row["j_position"]; $c_name = $row["c_name"]; $cperson = $row["c_name"]; $specialization = $row["specialization"]; $level = $row["level"]; $industry = $row["industry"]; $c_description = $row["c_description"]; $j_requirements = $row["j_requirements"]; $j_responsibilities = $row["j_responsibilities"]; $j_type = $row["j_type"]; $salary = $row["salary"]; $location = $row["location"]; $day_posted = $row["DAY(date_posted)"]; $month_posted = $row["MONTH(date_posted)"]; $year_posted = $row["YEAR(date_posted)"]; $day_closed = $row["DAY(date_closed)"]; $month_closed = $row["MONTH(date_closed)"]; $year_closed = $row["YEAR(date_closed)"]; $j_status = $row["j_status"]; $remarks = $row["remarks"]; ?> <input type="checkbox" name="jtype" value="<? if($_REQUEST['j_type']== 'Permanent') { print 'checked' ; }?>"> Permanent <input type="checkbox" name="jtype" value="<? if($_REQUEST['j_type']== 'Contract') { print 'checked' ; }?>"> Contract <input type="checkbox" name="jtype" value="<? if($_REQUEST['j_type']== 'Part Time') { print 'checked' ; }?>"> Part Time hope you could help me. its not yet working thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192971 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Looks to me your trying to make a Radio Button not check boxes.. Check boxes are True or False sence. 1 being true and 0 being false... Is it a Radio Button you Seek? Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192978 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 no, i need checkbox since the user has the option to select the 3 of them also hope you could help me with this Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192982 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Ok then you need more then just one (1) j_type... $j_type1 = $row['j_type1'] ; $j_type2 = $row['j_type2'] ; $j_type3 = $row['j_type3'] ; if ($j_type1 == 1) { $j_type1_ck = "checked" ; } else { $j_type1 = 0 ; $j_type1_ck = "" ; } if ($j_type2 == 1) { $j_type2_ck = "checked" ; } else { $j_type2 = 0 ; $j_type2_ck = "" ; } if ($j_type3 == 1) { $j_type3_ck = "checked" ; } else { $j_type3 = 0 ; $j_type3_ck = "" ; } <input type="checkbox" name="j_type1" value="<?php echo $j_type1 ; ?>" <?php echo $j_type1_ck ; ?>> <input type="checkbox" name="j_type2" value="<?php echo $j_type2 ; ?>" <?php echo $j_type2_ck ; ?>> <input type="checkbox" name="j_type3" value="<?php echo $j_type3 ; ?>" <?php echo $j_type3_ck ; ?>> Using that idea should fix you up.. You will need to have the other j_types in the database and 0 or 1 will do just fine. But if you need them to say Permanate etc then... if ($j_type1 == "Permanent") { $j_type1_ck = "checked" ; } else { $j_type1 = "" ; $j_type1_ck = "" ; } if ($j_type2 == "Contract") { $j_type2_ck = "checked" ; } else { $j_type2 = "" ; $j_type2_ck = "" ; } if ($j_type3 == "Part Time") { $j_type3_ck = "checked" ; } else { $j_type3 = "" ; $j_type3_ck = "" ; } That will do the trick for that if it need to be the words. Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-192988 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 sorry, i forgot to save my current updateform the name of the checkbox should be jtype[] since i will use implode in my process page for the jtype[] checkbox what can be the solution for this assuming that permanent, contract part time are the current values in my database? hope you could help me on this. thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193002 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 What I gave you should work wether you change the name="j_type1" to name="jtype1" for each check box name that is fine but the code above will do what you want. So are you saying your are going to use Explode and Implode to store jtype1 jtype2 and jtype3 into one row of the table? Why do it like? If you implode you will want to do it with a index like - so if all three jtypeX's were selected the entry into one row of the table will look like this Permanat-Contract-Part Time. This way you explode using - as the index. But if thats what you want then great.. But when you have the check boxes looking for if checked using the same jtype value they will all be checked. That is why you need to have values jtype1 jtype2 jtype3. Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193009 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 TRION, ok. I'll try this one. i'll let you know once it worked thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193020 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 TRION, i tried this one <? $jtype = $_GET['j_type']; { if ($jtype == "Permanent") { $j_type1_ck = "checked" ; } else { $j_type1_ck = "" ; } if ($jtype == "Contract") { $j_type2_ck = "checked" ; } else { $j_type2_ck = "" ; } if ($jtype == "Part Time") { $j_type3_ck = "checked" ; } else { $j_type3_ck = "" ; } } ?> <input type="checkbox" name="jtype[]" value="Permanent" <? echo $j_type_ck1 ; ?>> Permanent <input type="checkbox" name="jtype[]" value="Contract" <? echo $j_type_ck2 ; ?>> Contract <input type="checkbox" name="jtype[]" value="Part Time" <? echo $j_type_ck3 ; ?>> Part Time but its still not working by the way this is an update page and with that the value of the checkbox should not be taken from the database the only problem that i want to solve is if the value in the database for j_type is permanent contract part time the checkbox "checked" should be added to the checkbox line. hope you could help me with this. thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193052 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Look at your input check boxes you have the varibles all wrong.. You have "j_type_ck1" When you defined the varble to be "j_type1_ck" Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193054 Share on other sites More sharing options...
pixeltrace Posted February 24, 2007 Author Share Posted February 24, 2007 its still not working this is the code of my query <? include 'db_connect.php'; $query = mysql_query("SELECT staff_created, j_position, c_name, cperson, specialization, level, industry, c_description, j_requirements, j_responsibilities, j_type, salary, location, DAY(date_posted), MONTH(date_posted), YEAR(date_posted), DAY(date_closed), MONTH(date_closed), YEAR(date_closed), j_status, remarks FROM job_ads WHERE jobid= '$jobid'") or die(mysql_error()); $row = mysql_fetch_array( $query ); $staff_created = $row["staff_created"]; $j_position = $row["j_position"]; $c_name = $row["c_name"]; $cperson = $row["c_name"]; $specialization = $row["specialization"]; $level = $row["level"]; $industry = $row["industry"]; $c_description = $row["c_description"]; $j_requirements = $row["j_requirements"]; $j_responsibilities = $row["j_responsibilities"]; $j_type = $row["j_type"]; $salary = $row["salary"]; $location = $row["location"]; $day_posted = $row["DAY(date_posted)"]; $month_posted = $row["MONTH(date_posted)"]; //$month_posted1 = $row["MONTH(date_posted, %b)"]; $year_posted = $row["YEAR(date_posted)"]; $day_closed = $row["DAY(date_closed)"]; $month_closed = $row["MONTH(date_closed)"]; //$month_closed1 = $row["MONTH(date_closed, %b)"]; $year_closed = $row["YEAR(date_closed)"]; $j_status = $row["j_status"]; $remarks = $row["remarks"]; ?> and this is the code for my checkbox <? if ($j_type == "Permanent") { $j_type1_ck = "checked" ; } else { $j_type1_ck = "" ; } if ($j_type == "Contract") { $j_type2_ck = "checked" ; } else { $j_type2_ck = "" ; } if ($j_type == "Part Time") { $j_type3_ck = "checked" ; } else { $j_type3_ck = "" ; } ?> <input type="checkbox" name="jtype[]" value="Permanent" <? echo $j_type1_ck ; ?>> Permanent <input type="checkbox" name="jtype[]" value="Contract" <? echo $j_type2_ck ; ?>> Contract <input type="checkbox" name="jtype[]" value="Part Time" <? echo $j_type3_ck ; ?>> Part Time what could be wrong here? need help please! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193064 Share on other sites More sharing options...
TRI0N Posted February 24, 2007 Share Posted February 24, 2007 Again your still looking at just j_type in your query. You don't have any other j_type.. Your database needs j_type1 j_type2 j_type3 so that you can then assign those to the other 2 check boxes. You are looking at j_type and lets say its Part Time then only Part Time will show up checked. Quote Link to comment https://forums.phpfreaks.com/topic/39922-how-to-get-the-value-from-the-database-to-the-checkbox/#findComment-193070 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.