sophie17117 Posted June 27, 2007 Share Posted June 27, 2007 I'm trying to loop through values and insert them into $countries so that i can put $countries into a database field. :-\ at the moment i have a preview page that, once in my index page i have selected multiple options in a menu, the user submitts and the preview page prints the multiple selections using <?php foreach($country as $value)echo "$value."; ?><br /> i now need to put all those $values into one $countries array by looping through, but...i'm being blonde and really cant do it even though i no its simple!!! Students eigh! Quote Link to comment Share on other sites More sharing options...
sushant_d84 Posted June 27, 2007 Share Posted June 27, 2007 Hey ... For inserting into Array U need to use the Array_push function... Can u Tell me from where the $Country varaible comes live... I mean to say from which page the list is comming ... Or in other way u please exaplin u r procedure step by step... So That I can Guide u strongly ........... Sushant Quote Link to comment Share on other sites More sharing options...
sophie17117 Posted June 27, 2007 Author Share Posted June 27, 2007 I have got it to print all the values to screen its just inserting them into my database. This is the code section in the index- <tr><td><select multiple align= "left" name="country[]" size="2"> <option>IE</option> <option>NL</option> <option>UK</option> <option>ZA</option> </select></td> then i have a page called issue, which just prints out the users selection to the screen and then inserts it into the database- $countries[]=<?php foreach($country as $value)echo "$value."; ?><br /> insert bit- <?php $connect= mysql_connect('localhost','',''); if (!$connect) { echo("ERROR: Not connecting" . mysql_error() . "\n"); } mysql_select_db('sophie'); ?> <?php $insert = "INSERT INTO bulletin_data (RepDate, RepTime, Country, Service, StatusDesc, RefNo) VALUES ('$today','$time','$countries', '$services', '$status', '$refno')"; MYSQL_QUERY($insert) or die(mysql_error()); msql_close($connection); ?> when i call my insert statement i call $countries should i be using $country? Quote Link to comment Share on other sites More sharing options...
sushant_d84 Posted June 27, 2007 Share Posted June 27, 2007 Very First.... U r insert query should be in the Foreach Loop and otehr part of query .. except $countries remain same. and instead of $countries it will be $value.... In this way... there will be more than one records for selected contries... example if u have selected 4 countries .. and click on submit button u r code should insert 4 records........ which will have only countries different. U can not directly insert the whole list in mysql_query.. . I hope U got some idea about... This is the one way.... But really I dont like this method... Reply soon... let me know u r opinion. whatever maybe Quote Link to comment Share on other sites More sharing options...
sophie17117 Posted June 27, 2007 Author Share Posted June 27, 2007 ive had insider help!!! i'm inserting all of my array data into separate tables into my database linking them using join now. I dare say i'll hit another problem soon thanks Quote Link to comment Share on other sites More sharing options...
sushant_d84 Posted July 2, 2007 Share Posted July 2, 2007 Thats Gr8 ... I was also thinking for that Idea 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.