1 year ago
#364866
pok4
Accessing parent info with mustache php (two or more while cycles)
In first sorry for my bad english. I'm using mustache PHP and i started topic in github already - https://github.com/bobthecow/mustache.php/issues/396
I have 2 while cycles, here is the code:
$query_check = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."tickets ORDER by id DESC LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
$ticket_admin_form_array=[];//globalize
$ticket_admin_form_array2 = [];//globalize
$count = 0; //globalize
if ($query_check->rowCount() > 0) {
$tickets_found = true; //we found results
while ($row=$query_check->fetch(PDO::FETCH_ASSOC)) {
$tid = $row['id'];
$tq = $row['question'];
$open = $row['open'];
$category = $row['category'];
$username = $row['username'];
$date = date('d.m.y H:i:s', $row['date']);
$text = $row['text'];
$ticket_admin_form_array[]=[
'ext_the_tickets_tid'=>$tid,
'ext_the_tickets_cat'=>$category,
'ext_the_tickets_tq'=>$tq, //question
'ext_the_tickets_open_s'=>$open,
'ext_the_tickets_username'=>$username,
'ext_the_tickets_date'=>$date,
'ext_the_tickets_text'=>$text,
];
$get_all_msgs = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."tickets_comments WHERE tid='$tid' order by id ASC");
while ($row = $get_all_msgs->fetch(PDO::FETCH_ASSOC)) {
$textt = $row['text'];
$datet = date('d.m.y H:i:s', $row['date']);
$authored = $row['authored'];
$username = $row['username'];
if ($authored == 1) {
$authored = "($username):";
} else {
$authored = "<span style='color:red'>Administrator:</span>";
}
$count++; //we count the results and passing to array below
$ticket_admin_form_array2[$count][$tid]=[
'ext_the_tickets_authored'=>$authored,
'ext_the_tickets_datec'=>$datet,
'ext_the_tickets_textc'=>$textt,
];
}
My template file is:
{{#all_tickets_arr1}}
<div class="tickets_box t_{{ext_the_tickets_tid}}">[{{ext_the_tickets_cat}}] {{ext_the_tickets_tq}} | {{ext_the_tickets_lang_date}}: {{ext_the_tickets_date}} | {{ext_the_tickets_lang_status}}:
</div>
<div class="t_container_style t_cont_{{ext_the_tickets_tid}}" style="display:none">
<div class="t_new_msg_body">({{ext_the_tickets_username}}): ({{ext_the_tickets_date}}): <br/>{{ext_the_tickets_text}}</div>
{{#all_tickets_arr2}}
<div class="t_new_msg_body">{{&ext_the_tickets_authored}} ({{ext_the_tickets_datec}}): <br/>{{ext_the_tickets_textc}}</div>
{{/all_tickets_arr2}}
</div>
{{/all_tickets_arr1}}
i want to get unique results for every ticket. Now i get the same comments in every ticket which i started. In bottom i have this:
return $this->m->render(file_get_contents("ext/pok4/the_tickets/template/admin_form.html"), [
'all_tickets_arr1'=> new ArrayIterator($ticket_admin_form_array),
'all_tickets_arr2'=> new ArrayIterator($ticket_admin_form_array2),
'ext_the_tickets_pagination'=>($tickets_found) ? $pagination['output'] : '',
'ext_the_tickets_found_results'=>$tickets_found,
'ext_the_tickets_lang_date'=>$this->lang['ext_the_tickets_date'],
'ext_the_tickets_lang_status'=>$this->lang['ext_the_tickets_status'],
'ext_the_tickets_lang_welcome'=>$this->lang['ext_the_tickets_welcome'],
'ext_the_tickets_lang_open'=>$this->lang['ext_the_tickets_open'],
'ext_the_tickets_lang_closed'=>$this->lang['ext_the_tickets_closed'],
'ext_the_tickets_lang_send'=>$this->lang['ext_the_tickets_send'],
'ext_the_tickets_lang_ticket_closed_adm'=>$this->lang['ext_the_tickets_ticket_closed'],
'ext_the_tickets_lang_not_found'=>$this->lang['ext_the_tickets_no_tickets_for_now'],
]);
I use two array iterrators to passing it to mustache php.
'all_tickets_arr1'=> new ArrayIterator($ticket_admin_form_array),
'all_tickets_arr2'=> new ArrayIterator($ticket_admin_form_array2),
i want to to use ticket_id ($tid) and $count in templates for all_tickets_arr2 to get unique results for every ticket (unique comments i mean) Now as i said every ticket have the same comments.
The problem is here:
{{#all_tickets_arr2}}
<div class="t_new_msg_body">{{&ext_the_tickets_authored}} ({{ext_the_tickets_datec}}): <br/>{{ext_the_tickets_textc}}</div>
{{/all_tickets_arr2}}
this one must be something like this:
{{#all_tickets_arr2.count.tid}}
<div class="t_new_msg_body">{{&ext_the_tickets_authored}} ({{ext_the_tickets_datec}}): <br/>{{ext_the_tickets_textc}}</div>
{{/all_tickets_arr2.count.tid}}
i think... ? :)
can someone give me a advice what to do to make comments to show for every ticket uniquely ?
php
while-loop
mustache
cycle
0 Answers
Your Answer