Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Converting two cycles to smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Gestik
Smarty n00b


Joined: 02 Apr 2014
Posts: 3

PostPosted: Wed Apr 02, 2014 5:20 pm    Post subject: Converting two cycles to smarty Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Apr 02, 2014 8:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Gestik
Smarty n00b


Joined: 02 Apr 2014
Posts: 3

PostPosted: Thu Apr 03, 2014 4:46 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Apr 03, 2014 2:28 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Gestik
Smarty n00b


Joined: 02 Apr 2014
Posts: 3

PostPosted: Thu Apr 03, 2014 5:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP