I have a cell in one of my MySQL community edition 5.1 tables. The contents are always certain number(s). If there is more than one number, then it is delimited by an ;
semi-colon.
For example:
| Column |
1ar8fj
99dkek;adjidk3;dajdid
divdae;dadjid;
NULL
dkadjcud;dasd;adfkvdo
dkjfakj
...
I need make some code that takes each column value, splits it up by the ;
and then uses each value after it was split up to do another query, and output the results.
I know I can do this with PHP but I don't need to make this into a webpage, so I was wondering if this is possible write in MySQL syntax? The PHP code would look something like this:
<?php
$result = $mysqli->query('select column from table;');
while ($row = $result->fetch_array($result)){
$id_numbers = explode($row[0],';');
foreach($id_numbers as $key => $val){
// do another query
$result2 = $mysqli->query('select * from table2 where col_val = "'.$val.'"');
while ($row2 = $result2->fetch_array($result2){
echo $row2[0].'<br>';
}
}
}
?>
Is this possible directly in MySQL syntax?
Thanks!!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…