Jump to content

Values from an array, putting into database.


Northern Flame

Recommended Posts

I have values from an array which are a numbered values.

for example:

$array = array(1, 45, 67, 22, 86);

 

i want to put them into a column of my database like this:

 

1,45,67,22,86

 

just like that, all the numbers in the same column but separated

by commas.

 

how will i do that? will it be something like this:

 

$sql = "UPDATE table SET numbers = '";

foreach($array as $val){

$sql .= "$val,";

}

 

$sql .= "' WHERE id='$id'";

 

mysql_query($sql);

 

is there a smarter way of doing this?

or is that the correct way?

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.