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

Loop inside (another) loop (not connected by ID)

 
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
HalfSmart
Smarty n00b


Joined: 29 Jan 2014
Posts: 1

PostPosted: Wed Jan 29, 2014 12:58 am    Post subject: Loop inside (another) loop (not connected by ID) Reply with quote

Please, i need some help, i am new Smarty user, Smarty its great, but i am stuck on this for about 5 days.

Here is a example of the PHP code i am trying to convert:
Code:

$numone = "1";
$contest = $mysqli->prepare("SELECT `active`, `id`, `start`, `end`, `slots`, `description`, `name`, `type`, `minimum`  FROM `contests` WHERE `active` = ?");
$contest->bind_param('i', $numone);
$contest->execute();
$contest->bind_result($firstloop['active'], $firstloop['id'], $firstloop['start'], $firstloop['end'], $firstloop['slots'], $firstloop['description'], $firstloop['name'], $firstloop['type'], $firstloop['minimum']);
$contest->store_result();


if ($contest->num_rows() >0){
    $n=0;
    while($contest->fetch()){
    $n++;
        if ($firstloop['active'] == "1") {
            if ($firstloop['type'] == "0"){
   
         echo "
         <table>
         <tr><th colspan='2'>Contest name: ".$firstloop['name']." </th></tr>
         <tr><th>Contest Start: ".$firstloop['start']."</th><th> Contest End: ".$firstloop['end']." </th></tr>
         <tr><td>Description :<br> ".$firstloop['description']." </td></tr>
                 ";
          
         $participants = $mysqli->prepare("SELECT COUNT(*), `uid` FROM `completed` WHERE `status` = ? AND `time` > ? AND `time` < ?  AND `payment` >= ? GROUP BY `uid` ORDER BY count(*) DESC LIMIT ?");      
            $participants->bind_param('issii', $numone, $firstloop['start'], $firstloop['end'], $firstloop['minimum'], $firstloop['slots']);
            $participants->execute();
            $participants->bind_result($counted, $secondloop['uid']);
            $participants->store_result();
         
         echo "
         <tr><th>Place</th><th>ID</th><th>Completed</th></tr>
              ";
             while ($participants->fetch()){
            
         echo "
            <tr><td>".$n."</td><td>".$secondloop['uid']." </td><td> ".$counted."</td></tr>
                 ";         
            
            }
         echo  "
         </table>   
               ";
            }
        }
    }
}


And whatever i try i always fall at the end. Sad
As you can see, the both loops are not connected by ID.

If someone can help me, will save me one more night without sleep. Thanks
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