Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array_slice from one array into another

    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.

    PHP Code:
    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], 12);
                
    $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]); } 

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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

    PHP Code:
    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++;
             }


  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •