简体   繁体   中英

How can i get my code to recognize my array values?

I want to output my userdata in a html table. First I do a sql-query an get the multidimensional array 'users'. Now I want to output my data but I get an 'undefined variable: user' error in my html output. The array $users is known in my code. The error only appears in the frontend but not in the IDE.

<? foreach( $users as $user ): ?>
     <tr>
         <td><?= $user['M_ID'] ?></td>
         <td><?= $user['Username'] ?></td>
         <td><?= $user['E-Mail'] ?></td>
     </tr>
<? endforeach; ?>

The ability to use <? ?> <? ?> is defined in your php.ini file. likely your server php.ini config is not configed for supporting this. so change your code to :

<?php foreach( $users as $user ): ?>
     <tr>
         <td><?= $user['M_ID'] ?></td>
         <td><?= $user['Username'] ?></td>
         <td><?= $user['E-Mail'] ?></td>
     </tr>
<?php endforeach; ?>

also thanks to @jeto`s comment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM