modifiedcontent Posted October 23, 2008 Share Posted October 23, 2008 I have one generic 'records' table in MySQL. I want to add a category system with checkboxes, so you can store/find the records on multiple attributes. Apparently the right way to achieve this is to create 'categories' and 'lookup' tables. Then you also need implode/explode function to store/retrieve checkbox data. I have no clue how to put it all together. Does anyone know where I can find a working code example of this? Or a simple script that uses a category system with checkboxes (not pulldown)? Wordpress has the kind of multiple category system I'm looking for, but I have trouble reverse engineering how it works. Lots of sites refer back to this solution, but it's incomplete, full of errors and I can't get it to work. I'm looking for a simple, transparant working example. Link to comment https://forums.phpfreaks.com/topic/129860-multiple-category-system-checkbox-hell/ Share on other sites More sharing options...
redarrow Posted October 24, 2008 Share Posted October 24, 2008 here an example i worked on.... but your need to add a cheked=cheked method for the checkboxs.... got no idear how to add that....... if anybody wants to contubute a checkbox cheeking valadation example please do so... the code completly worrks but couldnt work out the chekbox valadation method sorry........ <?php echo"<table align='center'><tr><td align='left'><center><a href='".$_SERVER['PHP_SELF']."?cmd=a'>Select Cat!</a> <br><br></center></tr></td></table>"; if($_GET['cmd']=="a"){ $c=array("Food","Plants","Computers"); echo"<table align='center'><tr><td align='left'><form method='POST' action='".$_SERVER['PHP_SELF']."'>"; foreach($c as $cat){ echo"<tr><td><input type='checkbox' name='cat' value='$cat'>$cat<br></td></tr>"; } echo"<tr><td><br><br><input type='submit' name='submit' value='Choose Cat'><br><br></tr></td>"; echo"</form></center></table></td></tr>"; } if(isset($_POST['submit'])){ $cat=$_POST['cat']; switch($cat){ CASE "Food": $c=array("Burger","Chips","Sasuages"); echo"<table align='center'><tr><td align='left'><form method='POST' action='".$_SERVER['PHP_SELF']."'>"; foreach($c as $food){ echo"<tr><td><input type='checkbox' name='food' value='$food'>$food<br></td></tr>"; } echo"<tr><td><br><br><input type='submit' name='foods' value='Choose food'><br><br></td></tr>"; echo"</form><center></table></td></tr>"; BREAK; case "Plants": $c=array("Trulips","Rose","Sunflower"); echo"<table align='center'><tr><td align='left'><form method='POST' action='".$_SERVER['PHP_SELF']."'>"; foreach($c as $plant){ echo"<tr><td><input type='checkbox' name='plant' value='$plant'>$plant<br></center></td></tr>"; } echo"<tr><td><br><br><input type='submit' name='plants' value='Choose plants'><br><br></td></tr>"; echo"</form></center></table></tr></td>"; BREAK; case "Computers": $c=array("Apple","Pc","Atri"); echo"<table align='center'><tr><td align='left'><form method='POST' action='".$_SERVER['PHP_SELF']."'>"; foreach($c as $computers){ echo"<tr><td><input type='checkbox' name='computer' value='$computers'>$computers<br></td></tr>"; } echo"<tr><td><br><br><input type='submit' name='com' value='Choose computer'><br><br></td></tr>"; echo"</form></table></td></tr>"; BREAK; } } if($_POST['foods']){ $food=$_POST['food']; echo "<center><h1>$food</h1><center>"; switch($food){ CASE "Burger": echo" <center> <img src='http://tbn0.google.com/images?q=tbn:vorDPsJ-f6DBaM:http://brothersburger.com.ph/images/burger-pounder.jpg'></center>"; BREAK; CASE "Chips": echo "<center><img src='http://tbn0.google.com/images?q=tbn:FViS5OolWH005M:http://www.freefoto.com/images/9905/05/9905_05_31---Chips-with-salt-and-vinegar_web.jpg</center>"; BREAK; CASE "Sasuages": echo "<center><img src='http://tbn0.google.com/images?q=tbn:p6RaeFy06cxJpM:http://www.meandlous.com/images/Sasuage.jpg'></center>"; BREAK; } } if($_POST['plants']){ $plant=$_POST['plant']; echo "<center><h1>$plant</h1><center>"; switch($plant){ CASE "Trulips": echo" <center> <img src='http://tbn0.google.com/images?q=tbn:PUGaH5yNuRCDwM:http://artbymukkekawoman.com/gallery/gallery1-1.jpg'></center>"; BREAK; CASE "Rose": echo "<center><img src='http://tbn0.google.com/images?q=tbn:Pi3jJvWjSs5jZM:http://www.victorianrose.org/images/red_rose2.jpg'></center>"; BREAK; CASE "Sunflower": echo "<center><img src='http://tbn0.google.com/images?q=tbn:M5JqfoG53CMFdM:http://www.web-enz.co.nz/images/sunflowerAll.GIF'></center>"; BREAK; } } if($_POST['com']){ $computer=$_POST['computer']; echo "<center><h1>$computer</h1><center>"; switch($computer){ CASE "Apple": echo" <center> <img src='http://tbn0.google.com/images?q=tbn:hoAV9CG8skUBjM:http://www.katize.com/wp-content/uploads/2007/08/apple_computer_logosvg.png'></center>"; BREAK; CASE "Pc": echo "<center><img src='http://tbn0.google.com/images?q=tbn:BApwPL3NmoFSeM:http://www.cheaplaptops.org.uk/wp-content/laptopimg/2007/06/packard-bell-2391.jpg'></center>"; BREAK; CASE "Atri": echo "<center><img src='http://tbn0.google.com/images?q=tbn:tTZWky8jlKJZJM:http://www.arti.com.hk/media/logo.gif'></center>"; BREAK; } } ?> Link to comment https://forums.phpfreaks.com/topic/129860-multiple-category-system-checkbox-hell/#findComment-673505 Share on other sites More sharing options...
modifiedcontent Posted October 28, 2008 Author Share Posted October 28, 2008 Thanks so much redarrow! I'm very eager to try this!! Unfortunately I'll be stuck in other work for the next few days. I will get back to this thread later this week and report on any progress. I know checking the checkboxes is another annoying issue. I've collected lots of code examples about that. I should be able to puzzle something together. Link to comment https://forums.phpfreaks.com/topic/129860-multiple-category-system-checkbox-hell/#findComment-676331 Share on other sites More sharing options...
modifiedcontent Posted November 6, 2008 Author Share Posted November 6, 2008 OK, I finally got around to testing Redarrow's solution. It's just a cute checkbox script to select one picture from multiple options. It has nothing to do with the problem I described and it probably could have used a pulldown menu instead of checkboxes. I'm trying to put together a system where you can assign multiple category names from one MySQL table to records in another table. This should be a classic example of relational database + php in action, but I can't find a good clean transparant example anywhere. Wordpress has exactly what I need in their category system for the blog posts. I've been trying to reverse engineer that for the last two weeks. Is there no simple code example of this basic principle anywhere out there? Link to comment https://forums.phpfreaks.com/topic/129860-multiple-category-system-checkbox-hell/#findComment-683636 Share on other sites More sharing options...
MatthewJ Posted November 6, 2008 Share Posted November 6, 2008 Sounds like you should nail it down and do a tutorial Link to comment https://forums.phpfreaks.com/topic/129860-multiple-category-system-checkbox-hell/#findComment-683670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.