shane85 Posted April 6, 2010 Share Posted April 6, 2010 hey guys I have a table called host_locations. in this I have host_id location_name etc etc now I have a form that what im trying to do is display check boxes from the rows in this table. So for instance, say I had 4 rows in my table Java Hut Coffee Bean Joes Coffee Franks Coffe what id like to do is display these items with a checkbox next to them, so that the user in the form can select which location(s) they would like to chose, and then have this info stored into a different table which will be clients. In this table, there is a row called locations which this info needs to be stored in, I guess seperated by - so that I can do an explode statement later on to get the different locations out? My main problem is I also want to display a edit page where it will show the locations with the checkboxes checked off like they submited initially, however if they wish to uncheck one and update it, it will update the db. sorry for the long post..I posted this a few days ago which is where someone suggested $checkboxes = array('$check[0]', '$check[1]', '$check[2]', '$check[3]'); // values for your checkboxes foreach ($checkboxes as $key => $checkbox) { echo '<input type="checkbox" id="', $checkbox . $key, '" name="locations[]" value="', $checkbox, '"', (in_array($checkbox, $check) ? ' checked="checked"' : ''), '>', '<label for="', $checkbox . $key, '">', $checkbox, '</label>'; } however this doesnt work. just displays 4 checkboxes with the names $check[0] $check[1] etc beside it Quote Link to comment Share on other sites More sharing options...
frankienrg Posted April 6, 2010 Share Posted April 6, 2010 simple as a pie: $checkboxes = array($check[0], $check[1], $check[2], $check[3]); // values for your checkboxes foreach ($checkboxes as $key => $checkbox) { echo '<input type="checkbox" id="', $checkbox . $key, '" name="locations[]" value="', $checkbox, '"', (in_array($checkbox, $check) ? ' checked="checked"' : ''), '>', '<label for="', $checkbox . $key, '">', $checkbox, '</label>'; } Quote Link to comment Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 hmmm im using the following code $checkboxes = array($check[0], $check[1], $check[2], $check[3]); // values for checkboxes foreach ($checkboxes as $key => $checkbox) { echo '<input type="checkbox" id="', $checkbox . $key, '" name=".$arrEntry[advertising_locations]." value="', $checkbox, '"', (in_array($checkbox, $check) ? ' checked="checked"' : ''), '>', '<label for="', $checkbox . $key, '">', $checkbox, '</label>'; } and im getting the following to happen/error Warning: in_array() [function.in-array]: Wrong datatype for second argument in edit_client.php on line 50 line 50 is (in_array($checkbox, $check) ? ' checked="checked"' : ''), '>', and its also displaying 4 chekboxes, with a > before them Quote Link to comment Share on other sites More sharing options...
shane85 Posted April 7, 2010 Author Share Posted April 7, 2010 bump Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2010 Share Posted April 7, 2010 Most of those commas in the echo statement should be concatenation operators, no? echo '<input type="checkbox" id="', $checkbox . $key, '" name=".$arrEntry[advertising_locations]." value="', $checkbox, '"', Quote Link to comment Share on other sites More sharing options...
shane85 Posted April 7, 2010 Author Share Posted April 7, 2010 im not sure??? im a newbie still learning... Quote Link to comment Share on other sites More sharing options...
shane85 Posted April 7, 2010 Author Share Posted April 7, 2010 im not sure??? im a newbie still learning... Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 7, 2010 Share Posted April 7, 2010 $check is not an array, hence the error message; Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 7, 2010 Share Posted April 7, 2010 and you're all over the place in your question. I quickly skimmed over your question(?), and this was all that stuck out: I guess seperated by - so that I can do an explode statement later on to get the different locations out? that statement is a big no-no. keep your database normalized meaning: store items like locations in separate table (called locations?), with a relationship back to the user/owner of that location (typically in a users table). why? because if you ever want to be able to search for/by location(s), this is the easiest, most efficient method. otherwise, if you have all your locations in one record>field, you can't really search for the locations now, can you? try searching for: beverly-hills-new-york-chicago-baltimore-toronto Quote Link to comment Share on other sites More sharing options...
shane85 Posted April 7, 2010 Author Share Posted April 7, 2010 agreed. I was thinking about that today how difficult it is going to be to achieve that doing it with -....thnx for confirming that Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2010 Share Posted April 7, 2010 Off topic, but your avatar caption is hilarious They're more likely to win the America's Cup . . . Of course, being a Stars fan, I don't have much room to talk at this point, lol. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2010 Share Posted April 7, 2010 If no one helps you with this by tomorrow, I'll give you a hand. But at the moment, I need to go to sleep. Quote Link to comment 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.