Jump to content

How to add to an array


ollie007

Recommended Posts

Ok

 

A) You add it like this

$array[] = "Input";

 

B) You'd do it like

$array[] = mysql_real_escape_string($_POST[$string']);

 

The mysql_real_escape_string escapes the string, so it's no long a security risk

 

On a side note

$W00T = mysql_real_escape_string($_POST['200TH!']);

welll

 

when people post

 

data1,data2,data3 FROM one textarea

 

i would like it to be inserted into a database (already done), and THEN to be retrieved into an array,

 

ie  data1,data2,data3 into one cell !!!

 

So data from one cell delineated by comma BUT manipulated as single data entities??

 

Are we on the same page?

 

PS. I am NOT adding to the array the normal way like array[];

 

I am just gonna grab the data from the db and write out the array !!

 

$string='apples, oranges, bannana'

 

$array = ($string);

 

 

I am NOT adding to the array the normal way like array[];

 

I am just gonna grab the data from the db and write out the array !!

 

$string='apples, oranges, bannana'

 

$array = ($string);

 

the reverse of this to be honest

 

$sql= /*your sql data*/;
$data = array();
while($fetch = $mysql_fetch_array($sql))
{
$array = explode(',', $fetch['row']);
array_push($data, $array);
}

 

but i want to remove line breaks and add the commas where line breaks are

You mean like

$post = $_POST['textarea'];
$post = explode("\n", $post);

?

 

 

oooooh wait, you mean like....

 

$sql= /*your sql data*/;
$data = array();
while($fetch = $mysql_fetch_array($sql))
{
$array = explode(',', $fetch['row']);
array_push($data, $array);
}

 

Yeah, already suggested that. Apparently it's unsatisfactory though...

What do you actually want to do? Split on a space, line break, create from an array, fetch data from the database or what? You've suggested all of these and we've provided a solution.

 

I still don't understand what you actually want to do.

 

You're not being very clear...

 

 

And explode removes the delimiting character and creates an array of each part around it. You can read the manual for more info.

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.