I am fetching some of the datas from my database and one of my column has multiple entries from one user say col(col1) values(a,b,c). Now when I am selecting data from this database, my array looks like this,
Array
(
[0] => srt
[1] => qwe
[2] => xyz
[3] => abc
[4] => 1
)
Array
(
[0] => srt
[1] => qwe
[2] => xyz
[3] => abc
[4] => 2
)
Array
(
[0] => srt
[1] => qwe
[2] => xyz
[3] => abc
[4] => 3
)
Now as my array shows only fourth element of array is different.
I want to insert this data into another table which has different columns for different values means only one row corresponding to one user. Thus
col(col1) turns in to col(cola,colb,colc).
Now I want to insert like
cola -> 1,colb -> 2,colc -> 3.
But I am not able to access these values. If I select array[4] then it selects all four elements if I try this $array=array($result[4]); then it create an array of result but with same index value
Array ( [0] => 1 )
Array ( [0] => 2 )
Array ( [0] => 3 )
Array ( [0] => 4 )
I hope I am able to clarify my question.
So please suggest me some way so that I can access these values in some way.
Thanks !
EDIT
my code
while($result= mysql_fetch_array($select))
{
echo "<pre>";
print_r($result);
$array=array($result[4]);
echo "</pre>";
print_r($array);
my result
Array
(
[0] => suresh.galaxy@gmail.com
[email] => suresh.galaxy@gmail.com
[1] => 2011-01-06 13:00:36
[date_joined] => 2011-01-06 13:00:36
[2] => 1
[is_active] => 1
[3] => 1
[attribute_id] => 1
[4] => suresh
[info] => suresh
)
Array ( [0] => suresh )
Array
(
[0] => suresh.galaxy@gmail.com
[email] => suresh.galaxy@gmail.com
[1] => 2011-01-06 13:00:36
[date_joined] => 2011-01-06 13:00:36
[2] => 1
[is_active] => 1
[3] => 2
[attribute_id] => 2
[4] => patidar
[info] => patidar
)
Array ( [0] => patidar )
Array
(
[0] => suresh.galaxy@gmail.com
[email] => suresh.galaxy@gmail.com
[1] => 2011-01-06 13:00:36
[date_joined] => 2011-01-06 13:00:36
[2] => 1
[is_active] => 1
[3] => 4
[attribute_id] => 4
[4] => e5c59af60000c8dff51e4e9a315ab152:vN
[info] => e5c59af60000c8dff51e4e9a315ab152:vN
)
Array ( [0] => e5c59af60000c8dff51e4e9a315ab152:vN )
You could make a loop first, then from there you could slice the array after the loop
<?php
$arr = array();
while($result= mysql_fetch_array($select))
{
$arr[] = $result;
}
print_r($arr);
echo $arr[0][4] ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.