Jump to content

[SOLVED] Simple array help needed urgently


sophie17117

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/57382-solved-simple-array-help-needed-urgently/
Share on other sites

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.