I think that my code can be easier, but I’m not sure. Look and tell me please some alternative if you have. This code i using to show informations about movies
$sql='SELECT DISTINCT id,title,img,description,adder,added,
GROUP_CONCAT(DISTINCT cid,"-",caty ) AS caty,
GROUP_CONCAT(DISTINCT oid,"-",obs,"-",face,"-",rola,"-",typ) AS obs
FROM film
LEFT JOIN f_o ON f_o.f_id = film.id
LEFT JOIN obs ON f_o.o_id = obs.oid
WHERE film.id ='.$fid;
$wynik=mysql_fetch_assoc(mysql_query($sql));
if(isset($wynik['id'])){
echo '<pre>';
print_r($wynik);
echo '</pre>';
////
$array = explode(',', $wynik['obs']);
$r=array();//director - 0
$s=array();//Screenwriter - 1
$ak=array();//actors - 2
$akn=array();//actors 2 plan - 3
$np=array();//From Idea By - 4
$p=array();//producers - 5
$m=array();//music - 6
foreach ($array as $item)
{
$a = explode('-', $item);
if( $a[4] == 0 )
{
$r[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 1 )
{
$s[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 2 )
{
$ak[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 3 )
{
$akn[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 4 )
{
$np[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 5 )
{
$p[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
elseif($a[4] == 6 )
{
$m[] = $a[0].','.$a[1].','.$a[2].','.$a[3];
}
}
function dzielperson($data){
$i = 0;
$ile=count($data);
while ($i < $ile) {
$a = explode(",", $data[$i]);
$caty='<a href="/person/'.dolink($a[1]).'-'.$a[0].'" class="link1">'.$a[1].'</a>'.($i==($ile-1) ? '':', ');
$i++;
}
return $caty;
}
echo '<br>Title: '.$wynik[title];
echo '<br>Desription: '.$wynik[description];
echo '<br>directors: '.dzielperson($r);
echo '<br>screenwriters: '.dzielperson($s);
echo '<br>actors: '.dzielperson($ak);
echo '<br>actors 2 plan: '.dzielperson($akn);
echo '<br>From Idea By '.dzielperson($np);
echo '<br>Producers: '.dzielperson($p);
echo '<br>Music: '.dzielperson($m);
}
Here is mysql output:
Array
(
[id] => 1
[title] => Pirates
[img] => /images/1page_img1.jpg
[description] =>
[adder] => baambaam
[added] => 1349387322
[obs] => 1-aktor1-foto.jpg-shrek-3,2-aktor2-foto2.jpg-batman-0,3-aktor3-f1.png-Pirat-1,4-aktorzyna4-f2.png-Pirat 3-1
)
Tables structure:
film:id,title img,description,adder,added
obs:oid,obs,face,rola,typ
f_o:f_id,o_id
in column obs i have names of actors,directors….
It’s not completly code but i wish that you understand
P.S. I’m fixing your code for you for one reason: your original made me laugh for 10 minutes non-stop 🙂 Thank you.
P.P.S. I left some of the original mess behind, but take it as an opportunity to learn what was wrong with your code and try to simplify that yourself.
P.P.P.S. Yes, multiple queries in this case is better than single monster collecting unrelated stuff in single row.