How print text instead of a foreign key

27 views
Skip to first unread message

Аби Раджабова

unread,
Apr 28, 2017, 4:13:41 AM4/28/17
to redbeanphp

Hi. I have a problem with text output instead of foreign key.

$shared = R::findAll( 'template_workers');

echo ('<table class="table">
                <thead class="thead-inverse">
                    <tr> 
                        <th>#</th>
                        <th>Класс</th>
                    </tr>
                </thead> 
                <tbody>');
      foreach($shared as $row){
        echo '<tr>';
        echo '<th class="col col-lg-2">'.$row['id'].'</th>';
        echo '<td>'.$row['template_id'].'</td>'; 
        echo '<td>'.$row['workers_id'].'</td>'; 
    }
    echo ('</tbody></table>');

At output looks like this

# | phrase | name
1 |     1     |    1
2 |     2     |    2  
3 |     3     |    3

Any ideas what I'm doing wrong?
Thanks,
Abi
  

gabor

unread,
Apr 28, 2017, 4:19:57 AM4/28/17
to redbeanphp


Hi

I would suggest that instead of using $row['template_id'] you use $row['template']['name'], assuming your template has a name.

cheers
Gabor

John Walker II

unread,
Oct 26, 2017, 2:54:52 PM10/26/17
to redbeanphp
Really you shouldn't be accessing template_workers directly. That's a table meant to show a many to many relationship in between templates and workers.

If you want to find all the workers that a template has, it would be (I think)
foreach ($template->sharedWorkersList as $worker) {
  // do your worker related stuff.
};
(your mileage may vary, I'm doing this from memory.)

You can find more information here:  https://redbeanphp.com/index.php?p=/many_to_many
Reply all
Reply to author
Forward
0 new messages