Adastra Posted June 1, 2006 Share Posted June 1, 2006 I'm currently trying to wrap my mind around multiple categories. So far the whole selecting works perfectly fine, but I can't figure out the how to post everything to the catjoin table. I have three tables, the blog table, the blog_cat table with the id's & names of the categories and the blog_catjoin table with the id's of the entry and of the catID. I don't understand how to use the cat_array and foreach elements. Can someone help me out? My PHP knowledge is still very basic and PHP.net just confuses me. Thank you :)Relevant parts of the script (with some weird testing-stuff and some stuff commented out):Currently, this version posts both an entry to the blog table, but it only posts one category into the catjoin table (always the one with the highest ID), however, it should of course make seperate entries for each checked category checkbox. It would be terrific if someone could just show me what I have to do by editing this. I won't understand a thing if you try to explain it with theoretical stuff, I need to see it in use. [code]...# select the categories from the cat table to create a list of checkboxesinclude('connect.php');$result = mysql_query("SELECT blog_cat.catID, catname FROM blog_cat LEFT JOIN blog_catjoin ON blog_cat.catID=blog_catjoin.catID GROUP BY blog_cat.catID ORDER BY catname ASC") or print ("Can't select categories." . $result . "" . mysql_error());while($row = mysql_fetch_array($result)) {$catID = $row["catID"];$catname = $row["catname"];echo "<.input type=\"checkbox\" name=\"$cat_array\" value=\"$catID\"";echo " /> $catname ";}....<./form>....# insert all the stuff into the database$sql = "INSERT INTO $table (...) VALUES (....)";$result = mysql_query($sql) or print ("Unable to post data." . $sql . "" . mysql_error());if ($result != false) {print "Entry has been posted! ($title)";}$idresult = mysql_query("SELECT id from $table ORDER by id DESC LIMIT 1") or print ("Can't select categories." . $result . "" . mysql_error());while($idrow = mysql_fetch_array($idresult)) {$id = $idrow["id"];}/*foreach ($cat_array as $cat) {*/$query_cat = "INSERT INTO blog_catjoin VALUES ('','$id','$catID')";$result_cat = mysql_query($query_cat);if ($result_cat != false) {echo "All categories successfully added.";}/*}*/}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10988-need-help-with-multiple-categories/ Share on other sites More sharing options...
Adastra Posted June 2, 2006 Author Share Posted June 2, 2006 Anyone? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] I know posting checkbox data to a db isn't THAT difficult. I just have no clue how to 'make it work' in my script here. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/10988-need-help-with-multiple-categories/#findComment-41145 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.