skoobi Posted February 19, 2010 Share Posted February 19, 2010 Hi im struggling to find a way to list a few items and have a checkbox next to them to select it... Basicly i have a web form for orders which it willl display a list of the specials from a database and it will be in list format and you then choose which items in that list... example: Soup of the day || (Checkbox) Prawn Salad || (Checkbox) The difficult part which i cannot get my head around is populating the list with the data from the database... Any help would be greatful... Cheers Chris Quote Link to comment https://forums.phpfreaks.com/topic/192627-checkboxes-and-mysql/ Share on other sites More sharing options...
Wolphie Posted February 19, 2010 Share Posted February 19, 2010 Why can't you just place a check box next to it? <?php $sql = mysql_query("SELECT * FROM menu"); echo '<table>'; while ($item = mysql_fetch_object($sql)) { echo '<td>'. $item->name .'</td>'; echo '<td><input type="checkbox" name="selected[\''. $item->name .'\']" />'; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/192627-checkboxes-and-mysql/#findComment-1014791 Share on other sites More sharing options...
skoobi Posted February 19, 2010 Author Share Posted February 19, 2010 Ive tried that and it gives me this error 'Warning: mysql_fetch_object() expects parameter 1 to be resource, boolean given in starters.php on line 19' Heres the db table names. Table Name : starters Column names : id, starter, extra Cheers Chris Quote Link to comment https://forums.phpfreaks.com/topic/192627-checkboxes-and-mysql/#findComment-1014794 Share on other sites More sharing options...
Wolphie Posted February 19, 2010 Share Posted February 19, 2010 <?php $sql = mysql_query("SELECT * FROM starters"); echo '<table>'; while ($item = mysql_fetch_object($sql)) { echo '<td>'. $item->starter .'</td>'; echo '<td><input type="checkbox" name="selected[\''. $item->starter .'\']" />'; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/192627-checkboxes-and-mysql/#findComment-1014817 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.