In phpMyAdmin, I am writing
SELECT `class` FROM `teachers` WHERE `var1`=3;
I can give results. The Results are 5,6,7,8,9,10. I am Trying this code in Sublimetext3. code is like this :
<tr>
<?php
$classlistdata = $db->getrows("SELECT `class` FROM `teachers` WHERE `var1`=3; ");
foreach ($classlistdata as $ndcld) {
?>
<td height="25" colspan="3" ><span class="admin"><?php echo ($ndcld); ?></span></td>
<?php } ?>
</tr>
this code writing 6 times "array" . How can I fix it. I am new PHP. thanks for your answer.
您应该使用echo $ndcld['class'];
I don't know whats behind the getrows
method, but likely its just an normal SQL query since you get arrays. Well, in your case, ndcld
is an array. An array containing all the queried attributes as an array key.
Change your code to:
$classlistdata = $db->getrows("SELECT `class` FROM `teachers` WHERE `var1`=3; ");
foreach ($classlistdata as $ndcld) {
?>
<td height="25" colspan="3" ><span class="admin"><?php echo $ndcld["class"]; ?></span></td>
<?php } ?>
That should do the job ;)
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.