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
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.