mbrown Posted September 17, 2008 Share Posted September 17, 2008 I am just double checking, can i use the explode() function to help insert information into my database i have a field that is set to field of study where they can enter more than one field separated by a comma (,). Is there a way that I can use the explode() function to get each one in a separate line in the database? For example they enter: Network Technology, Computer Technical Support, Network Specialist In the database table that I am saving all the information there is a column called Field of Study I would like it to be displayed this way: Network Technology Computer Technical Support Network Specialist not this way Network Technology, Computer Technical Support, Network Specialist Thanks Mbrown Quote Link to comment https://forums.phpfreaks.com/topic/124645-solved-explode-with-database-insertion/ Share on other sites More sharing options...
Maq Posted September 17, 2008 Share Posted September 17, 2008 Yes, after you explode the string with the delimiter of ',' it will divide up all three of those fields into pieces. So: $pieces[0] = Network Technology; $pieces[1] = Computer Technical Support; $pieces[2] = Network Specialist; Now you can insert however you want, even by adding line breaks in. Quote Link to comment https://forums.phpfreaks.com/topic/124645-solved-explode-with-database-insertion/#findComment-643741 Share on other sites More sharing options...
mbrown Posted September 17, 2008 Author Share Posted September 17, 2008 I am currently in the lab and did not bring my php book I am taught from. Could you please give me an example. The variable I am currently using for field of study is $FieldofStudy. thank you Quote Link to comment https://forums.phpfreaks.com/topic/124645-solved-explode-with-database-insertion/#findComment-643745 Share on other sites More sharing options...
mbrown Posted September 17, 2008 Author Share Posted September 17, 2008 since i can not modify to add some information to my last post, i will try to do it later on this afternoon and post it and see if what you guys think. thank you Quote Link to comment https://forums.phpfreaks.com/topic/124645-solved-explode-with-database-insertion/#findComment-643789 Share on other sites More sharing options...
mbrown Posted September 17, 2008 Author Share Posted September 17, 2008 This is in my validate.php .... //replace the ", " with a new line character in the database //table column for field of study $FieldofStudyArray = explode (", ", $FieldofStudy); foreach ($FieldofStudyArray as $FieldsofStudy) .... this is in my insert.php .... <body> <?php $query = "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy<br />', '$GPA');"; mysqli_query($db, $query) or die(mysqli_error($db) . '<br />' . $query);?> .... I can show you what i have in my getdata.php which just shows the information in my database so i dont need to go into the phpmyadmin area for quickness sake. any help would be great Quote Link to comment https://forums.phpfreaks.com/topic/124645-solved-explode-with-database-insertion/#findComment-643992 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.