|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Gestik Smarty n00b
Joined: 02 Apr 2014 Posts: 3
|
Posted: Wed Apr 02, 2014 5:20 pm Post subject: Converting two cycles to smarty |
|
|
Hello.
I have two cycles in PHP, that I needed converting to smarty structure. Down includes PHP code.
Code: |
$query = mysqli_query($cnn, "SELECT *, COUNT(*) AS ph FROM course INNER JOIN completed_course ON course.id = completed_course.id_course GROUP BY course.id");
while ($row = mysqli_fetch_array($query)){ ?>
<tr> <td> <?php echo $row['id']; ?></td><td> <?php echo $row['nazev']; ?> </td><td> <?php echo $row['ph']; ?> </td> <td>
<?php
$Number_of_graduates = mysqli_query($cnn, "SELECT COUNT(*) AS abs FROM participant where id_completed_course = $row[id]");
while ($rAbs = mysqli_fetch_array($Number_of_graduates)){
echo $rAbs['abs'];
} ?>
</td>
<?php }
|
Please with help. Thank you. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Apr 02, 2014 8:47 pm Post subject: |
|
|
Here is a start. You can finish the template.
Code: | $query = mysqli_query($cnn, "SELECT *, COUNT(*) AS ph FROM course INNER JOIN completed_course ON course.id = completed_course.id_course GROUP BY course.id");
while ($row = mysqli_fetch_array($query)) {
$rows[] = $row;
}
$smarty->assign('rows', $rows);
$smarty->display('index.tpl'); |
Code: | {foreach $rows as $row}
<tr><td>{$row.id}</td></tr>
{/foreach} |
|
|
Back to top |
|
Gestik Smarty n00b
Joined: 02 Apr 2014 Posts: 3
|
Posted: Thu Apr 03, 2014 4:46 am Post subject: |
|
|
mohrt wrote: | Here is a start. You can finish the template.
Code: | $query = mysqli_query($cnn, "SELECT *, COUNT(*) AS ph FROM course INNER JOIN completed_course ON course.id = completed_course.id_course GROUP BY course.id");
while ($row = mysqli_fetch_array($query)) {
$rows[] = $row;
}
$smarty->assign('rows', $rows);
$smarty->display('index.tpl'); |
Code: | {foreach $rows as $row}
<tr><td>{$row.id}</td></tr>
{/foreach} |
|
How it exactly I have. But the more I need to add this code still select the second. and I can not. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 03, 2014 2:28 pm Post subject: |
|
|
I didn't see the 2nd query in there. It is just grabbing the count(*), so no need to while() loop it. Something like:
Code: | $query = mysqli_query($cnn, "SELECT *, COUNT(*) AS ph FROM course INNER JOIN completed_course ON course.id = completed_course.id_course GROUP BY course.id");
while ($row = mysqli_fetch_array($query)) {
$Number_of_graduates = mysqli_query($cnn, "SELECT COUNT(*) AS abs FROM participant where id_completed_course = $row[id]");
$abs = mysqli_fetch_array($Number_of_graduates));
$row['abs']= $abs[0];
$rows[] = $row;
}
$smarty->assign('rows',$rows);
$smarty->display('index.tpl'); |
index.tpl:
Code: | {foreach $rows as $row}
{$row.id}
{$row.abs}
{/foreach} |
|
|
Back to top |
|
Gestik Smarty n00b
Joined: 02 Apr 2014 Posts: 3
|
Posted: Thu Apr 03, 2014 5:45 pm Post subject: |
|
|
mohrt wrote: | I didn't see the 2nd query in there. It is just grabbing the count(*), so no need to while() loop it. Something like:
Code: | $query = mysqli_query($cnn, "SELECT *, COUNT(*) AS ph FROM course INNER JOIN completed_course ON course.id = completed_course.id_course GROUP BY course.id");
while ($row = mysqli_fetch_array($query)) {
$Number_of_graduates = mysqli_query($cnn, "SELECT COUNT(*) AS abs FROM participant where id_completed_course = $row[id]");
$abs = mysqli_fetch_array($Number_of_graduates));
$row['abs']= $abs[0];
$rows[] = $row;
}
$smarty->assign('rows',$rows);
$smarty->display('index.tpl'); |
index.tpl:
Code: | {foreach $rows as $row}
{$row.id}
{$row.abs}
{/foreach} |
|
I have rather help, as the value of ID from the first sql query to get the second query as WHERE |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|