c_shelswell Posted December 13, 2006 Share Posted December 13, 2006 I'm trying to add a number of fields to mysql but getting myself in a muddle with the foreach statement.I've got a whole load of postdatalike: array ([title1]=> "title", [picture1]=> "pic1.jpg", [title2]=>"title2", [picture2]=> "pic2.jpg",)etc. There's acutally a whole load more data than this. I was hoping to write a foreach to add from title to pic and whatever else is inbetween then start a new query for title2. is this possible? i couldn't figure it out using foreach. At the moment i'm just creating a variable for each one i.e. $title1 = $_POST['title1'] but it's a little long winded.thanks for any help Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Share Posted December 13, 2006 Not entirely sure what you want to do. But you can use this to do something to all the values of $_POST.[code]foreach ($_POST as $key => $value) { what ever you want to do with the values of the postdata. }[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 13, 2006 Share Posted December 13, 2006 If you just want to get all of the variable out of $_POST, use extract.http://www.php.net/extractIf you are wanting to use a loop for the number of pictures:[code]$picture_count = 10;for ($a = 1; $a <= $picture_count; $a++) { echo "title" . $a . ": " . $_POST['title' . $a] . " - picture" . $a . ": " . $_POST['picture' . $a] . "<br />";}[/code]That's the general idea anyway. Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted December 13, 2006 Author Share Posted December 13, 2006 cheers hitman that should do the job. 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.