php - Looking for some kind of "lookahead iteration" for grouping record sets -
as use be, if need display list of on site have use looping construct iterate on data.
in case it's foreach() on <tr>
of table
foreach($candidates $candidate)
and after getting values:
$candidate->id
problem 1 specific value, , enforcement. in db have data in table below, example candidates_id
= 600 there enforcemement 1 , 0
id | candidates_id | enforcement ------------------------------------- 1 | 598 | 2 2 | 599 | 4 3 | 600 | 1 4 | 600 | 0
until okey, values db , echo on site. problem values 0 or 1 have no meaning end user. write if / else condition
if($candidate->enfor == 0) echo "text1"; elseif($candidate->enfor == 1) echo "text2"; else echo "some default text";
in sample data there 2 records candidates_id=600 , different values enforcement.
right script produces 2 separate <tr>
elements. 1 containing <td>text1</td>
, other <td>text2</td>
.
i'm looking way output <td>text1,text2</td>
in same html table row , column based on fact there 2 records candidate_id=600 in database.
try make cycle without success. not sure if thinking right way.
can advise me how make work?
edit: query db is:
select c.id, c.firstname, c.surname, c.email, c.process, c.search_work, c.note,c.registration_date, max(case when cl.language = 'angličtina' cl.level else '-' end)as 'en', max(case when cl.language = 'němčina' cl.level else '-' end)as 'ge', group_concat(distinct ce.enforcement) enfor, group_concat(distinct cc.city) city candidates c left join candidates_languages cl on c.id = cl.candidates_id left join candidates_enforcement ce on c.id = ce.candidates_id left join candidates_city cc on c.id = cc.candidates_id group c.id, c.firstname, c.surname, c.email desc
the situation group_concat
in query return 0,1
id=600
. should this:
foreach($candidates $candidate){ // things ... $enfor_array = explode(',', $candidate->enfor); foreach($enfor_array $enf) { if($enf == 0) echo "text1"; elseif($enf == 1) echo "text2"; else echo "some default text"; } }
Comments
Post a Comment