1

How can i explode [group_concat(DISTINCT LineItem.ItemID)] => 600278,WH1502.

I tried this but displays nothing

$result = mysqli_query($con,"SELECT ...")

while($row = mysqli_fetch_array($result)) { 
$r = $row[LineItem.ItemID];
 explode(',',$r);
}

Also tried

$result = mysqli_query($con,"SELECT ...")

while($row = mysqli_fetch_array($result)) {
   $r = $row[group_concat(DISTINCT LineItem.ItemID)];
   explode(',',$r);
 }

//ARRAY

  Array ( 
        [0] => XXOR001# 
        [CustomerID] => XXOR001# 
        [1] => XXXX INDUSTRIES 
        [Customer_Bill_Name] => XXX INDUSTRIES 
        [2] => WILL CALL [WhichShipVia] => WILL CALL [3] => 
        [INV_POSOOrderNumber] => [4] => 2014-12-05 
        [ShipByDate] => 2014-12-05 [5] => 
        [GoodThruDate] => [6] => 
        [CustomerSONo] => [7] => 15001 
        [Reference] => 15001 [8] => 2014-11-17 
        [TransactionDate] => 2014-11-17 [9] => 1 
        [DistNumber] => 1 
        [10] => 30.0000000000000000000 
        [Quantity] => 30.0000000000000000000 
        [11] => 600278,WH1502 
        [group_concat(DISTINCT LineItem.ItemID)] => 600278,WH1502 
        [12] => ASSY400/60-15.5/14 TRCIMP 15.5X13 8-8 FLAT, BW (TW4155-2)  
        [SalesDescription] => ASSY400/60-15.5/14 TRCIMP 15.5X13 8-8 FLAT, BW (TW4155-2)
        [13] => TW4155-2 
        [PartNumber] => TW4155-2 [14] => ASSY400/60-15.5/14W/WHL15.5X13 
        [ItemDescription] => ASSY400/60-15.5/14W/WHL15.5X13 ) 
1
  • Change your group_concat(DISTINCT LineItem.ItemID) in your SELECT query to an alias -> group_concat(DISTINCT LineItem.ItemID) as ItemIDgroup, then use the alias in the explode -> $r = $row['ItemIDgroup']; explode(',',$r); Commented Nov 30, 2014 at 0:46

1 Answer 1

3

I'm not sure what you are trying to do, but you could try something like this to help provide some visibility to your code:

while($row = mysqli_fetch_array($result)) { 
    $r = $row[LineItem.ItemID];
    $lineItemArray = explode(',',$r);
    print_r($lineItemArray);
}

explode() creates an array from a string based on the assigned separator. Consider this example:

$r = '600278,WH1502';
$rarray = explode(',',$r);
print_r($rarray);

//Output:
Array
(
    [0] => 600278
    [1] => WH1502
)

See demo

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Mark How can i store the field LineItem.ItemID in $r instead of $r = '600278,WH1502';?
Thanks Mark but I dont get it why doesnt print $lineItemArray. I tried exactly the same the code you put above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.