gmc1103 Posted October 27, 2015 Share Posted October 27, 2015 Hi I'm having a problem getting the user_id into a table td This is my php <?php if (empty($results)) { } else { foreach ($results as $row) { echo "<tr><td>"; echo $row['user_nome']; echo "</td><td>"; echo $row['user_email']; echo "</td><td>"; echo $row['user_tel']; echo '<td><a data-toggle="modal" data-id="echo $row['user_id']" class="open-AddDialog btn btn-sm btn-danger center-block" href="#myModal">Validar</a></td>'; } } ?> Giving me error in this line echo '<td><a data-toggle="modal" data-id="echo $row['user_id']" class="open-AddDialog btn btn-sm btn-danger center-block" href="#myModal">Validar</a></td>'; unexpected echo Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 27, 2015 Share Posted October 27, 2015 (edited) You have an 'echo' inside the quoted text. Couple that with the fact that you start the string with a single quote and then put an array with a single quoted index inside the string, the PHP parser is confused (as am I). Also, why do you have this? if (empty($results)) { } else { There is no purpose for the TRUE branch of that statement. Just use this ]if (!empty($results)) { Although, if $results is just an empty array, you don't need the empty check at all - just run the foreach. EDIT: You are also creating some invalid HTML code. There is no closing TD for one element - and I would expect a closing TR on each foreach as well. Edited October 27, 2015 by Psycho Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted October 27, 2015 Solution Share Posted October 27, 2015 Give this a try <?php if (!empty($results)) { foreach ($results as $row) { echo "<tr>\n" echo " <td>{$row['user_nome']}</td>\n"; echo " <td>{$row['user_email']}</td>\n"; echo " <td>{$row['user_tel']}</td>\n"; echo " <td><a data-toggle='modal' data-id='{$row['user_id']}' class='open-AddDialog btn btn-sm btn-danger center-block' href='#myModal'>Validar</a></td>\n"; echo "</tr>\n" } } ?> 1 Quote Link to comment Share on other sites More sharing options...
gmc1103 Posted October 27, 2015 Author Share Posted October 27, 2015 Thanks Psycho You are the man...Thank you, learning everyday. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.