Hi
Mysql does not have something like “split” function so my idea is that you can either:
- Create your own mysql function
or
- Join fielsd in PHP like:
1)create arrays from sql query
[code]$sqlCommand=mysql_query(“select * from command”)or die (mysql_error());
$sqlReader=mysql_query(“select * from reader”)or die (mysql_error());
$i=0;
while(mysql_fetch_assoc($sqlReader))
{
$array[mysql_result($sqlReader,$i,0)]=mysql_result($sqlReader,$i,1);
$i++;
}
$i=0;
while(mysql_fetch_assoc($sqlCommand))
{
$arrayc[mysql_result($sqlCommand,$i,0)]=array(“type_id” => mysql_result($sqlCommand,$i,1),“reader” => getReader(mysql_result($sqlCommand,$i,2),$array),“result” => mysql_result($sqlCommand,$i,3),“error” => mysql_result($sqlCommand,$i,4));
$i++;
}[/code]
- use function to get the real names
/**
* function return names from array
* $string - string from sql with keys
* $array - array of names
*/
function getReader($string,$array){
$string=explode(",",$string);
foreach ($string as $str){
$reader[]=$array[$str];
}
return implode(",",$reader);
}
(code above might not be the prettiest
)
I suggest to you to store data differently. Instead of store (‘1’,‘1’,‘1,2,3’,‘1’,‘ok’) store this:
Reader 1 (‘1’,‘1’,‘1’,‘1’,‘ok’)
Reader 2 (‘1’,‘1’,‘2’,‘1’,‘ok’)
Reader 3 (‘1’,‘1’,‘3’,‘1’,‘ok’)
and if you want to get all those three readers together in one row, you can use concat function
concat_ws(", ",readers)
or
GROUP_CONCAT( readers ORDER BY command.readers separator ’ ') … group by id
Hope it helps