I'm trying to substring a mysql query result to get my seperate data columns. My delimiter is the character "||" that will separate each result. I'm searching online and can't seem to find a source that will substring a mysql result. I always find that it substring the columns from the table. Is this possible using substring?
I've created 2 tables which is number and sample:
Table sample
Table number
Here's my query:
SELECT sample.id,
SUBSTRING_INDEX(SUBSTRING_INDEX(sample.DESCRIPTION, '::', numbers.n), '::', -1) AS DETAIL
FROM numbers
INNER JOIN sample ON CHAR_LENGTH(sample.DESCRIPTION) -CHAR_LENGTH(REPLACE(sample.DESCRIPTION, '::', ''))>=numbers.n-1
ORDER BY id,
n
Here's my result query
Here's my expected result
Update
I've tried to do this in PHP and I've made another progress. However, I'm getting an undefined offset.
Code:
$querydata = "SELECT DESCRIPTION from sample";
$resultdata = $conn->prepare($querydata);
$resultdata->execute();
$storeresult = $resultdata->fetchObject();
$resultquery = $storeresult->DESCRIPTION;
$pieces = explode("::",$resultquery);
$countVal = count($pieces);
$counter = 0;
$counter1 = 1;
$counter2 = 0;
while($counter<$countVal){
$pieces1 = explode("||", $pieces[$counter]);
$pieces2 = explode("||", $pieces[$counter]);
$pieces3 = explode("||", $pieces[$counter2]);
echo $pieces1[0]."<br>"; // detail
echo $pieces2[1]."<br>"; // response
$counter++;
$rowCount++;
}