...

View Full Version : array_slice from one array into another



jlhamma
03-10-2010, 10:14 PM
I'm pulling data from a query into an array for one use. But I need to put the 2nd field into another array for a different use. Using a print function just to see results. Results look like this:
Array ( [tID] => 61 [0] => J20 ) Array ( [tID] => 62 [0] => J21 ) Array ( [tID] => 63 [0] => J22 )

I need the last elements (J20, J21, J22). How do I return just those to use later?
$id_data is what I'm looking at.


if (!empty($query_prod)) {
$i=0;
$n=0;
while($row = mysql_fetch_array($query_prod)) {
$xls_data[$i] = $row;
$id_data[$n] = $xls_data[$i];
$id_data[$n] = array_slice($id_data[$n], 1, 2);
$i++; $n++; }

for($i = 0; $i < sizeof($xls_data);$i++) {
$i = printTableRow4($xls_data[$i],$i); }

for($n = 0; $n < sizeof($id_data);$n++) {
print_r($id_data[$n]); }

Fumigator
03-10-2010, 10:25 PM
Can't you just assign query results to the second array in your "while" loop? I'm assuming you know the column name where that



if (!empty($query_prod)) {
$i=0;
while($row = mysql_fetch_array($query_prod)) {
$xls_data[$i] = $row;
$id_data[$i] = $row['column_you_want'];
$i++;
}
}

jlhamma
03-10-2010, 11:53 PM
Oh man do I feel dumb. It's been a long day. Been trying to create a mountain out of a mole hill.

Thanks for waking me up!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum