gamerzfuse Posted May 8, 2009 Share Posted May 8, 2009 <input type="checkbox" id="heatedseats" name= "heatedseats" disabled="disabled" value= "<?php $vehicles->heatedseats->ViewValue ?>"/> This is essentially what I want to do (but this checkbox does not return the value from the database) I have a databast called vehicles, a field called heatedseats and I want to take the tinyint value from that field (1 or 0) and display it as a checkbox, checked or unchecked, but also disable to checking. This is for a features list. Thanks! Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/ Share on other sites More sharing options...
GingerRobot Posted May 8, 2009 Share Posted May 8, 2009 You must set the checked attribute to checked if you want the check-box pre checked. (Do i win an award for most extensive use of the word checked in one sentence?) e.g.: <?php $yourValueFromDb = 1; $checked = ($yourValueFromDb == 1) ? 'checked="checked"' : ''; echo '<input type="checkbox" id="heatedseats" name= "heatedseats" disabled="disabled" '.$checked.' "/>'; ?> I wrote a tutorial about working with check-boxes and databases, which you might like to read: http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-829715 Share on other sites More sharing options...
gamerzfuse Posted May 8, 2009 Author Share Posted May 8, 2009 I just don't understand this line: $yourValueFromDb = 1; How does this value work, or how do I ask the database if the value =1? Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-829717 Share on other sites More sharing options...
GingerRobot Posted May 8, 2009 Share Posted May 8, 2009 I just don't understand this line: $yourValueFromDb = 1; How does this value work, or how do I ask the database if the value =1? Indeed. It was just for demonstration. I'm assuming you'll be generating these checkboxes in a loop in any case. Try the tutorial above, it really will help - you'll not need the part which shows you how to update the database with the checkboxes, but the rest is relevant Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-829720 Share on other sites More sharing options...
gamerzfuse Posted May 8, 2009 Author Share Posted May 8, 2009 I read the tutorial, but it all seems complicated to me. I have already setup a form to enter a 1 if the box is checked and a 0 if the box is unchecked. Is there no simple line of code to then retrieve this? Something like: <?php $heatedseats = $vehicles->heatedseats->ViewValue if $heatedseats == "1" { $checked = ? 'checked="checked"'; } ?> ? Thanks for you help! Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-829728 Share on other sites More sharing options...
gamerzfuse Posted May 9, 2009 Author Share Posted May 9, 2009 Finally figured this one out. Almost solved, one last question: Any way to make a disabled checkbox less.. grey? It's very difficult to see a disable checkbox. Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-830352 Share on other sites More sharing options...
gamerzfuse Posted May 9, 2009 Author Share Posted May 9, 2009 onclick="return false;" Did the trick. Link to comment https://forums.phpfreaks.com/topic/157395-solved-checkbox-displaying-from-database/#findComment-830403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.