Welcome Guest, Not a member yet? Register   Sign In
2 foreach loops

(This post was last modified: 06-07-2021, 12:32 AM by Lipe_Bogaci.)

How can i add 2 foreach loops in same table? One loop for users and another for user roles

[font=Consolas, "Courier New", monospace]<?php foreach($users as $row): ?>
  <td class="text-center"><?=$row['role_id']?></td>[/font]

[font=Consolas, "Courier New", monospace][font=Consolas, "Courier New", monospace]</tr>[/font][/font]
[font=Consolas, "Courier New", monospace]<?php endforeach?>[/font]

(This post was last modified: 06-07-2021, 09:16 AM by captain-sensible.)

if in a controller you assign data in the form $data = [ 'user'=>$usr,
//then i dont see why you can't also add :

in which case you only need one foreach loop in a view

but you can do things such as in view:

foreach($result as $res)
// $result is whats passed from controller and is an array, $res is a convient var to pass put
echo "<td>". $res["first_name"]. " ".$res["last_name"]. " </td> ";

foreach($result2 as $res2)

echo "<td>". $res2["someDbColumn"]." ".$res2["something_else"]."</td";

// the php code will just get processed in a linear manner

SO you can have two foreach in a single table; however the main problem is going to be lining things up
or you have to use "dummy" <td> </td> to fill in the gaps containing perhaps &nbsp; which is none breaking space code

you want merg two associates arreay to gather


Or join two table select columns you need

Theme © iAndrew 2016 - Forum software by © MyBB