0

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.

3
  • 1
    What is the array you're getting in result? print_r($ndcld); will show you all the items of that array Commented Feb 8, 2018 at 15:03
  • 1
    getrows could be used to return more than one column, so each row is probably an array of values with one item. Im not into PHP but in c# you would get it ndcld["class"] Commented Feb 8, 2018 at 16:01
  • btw, I wonder if this aint duplicated... Commented Feb 8, 2018 at 16:02

2 Answers 2

3

You should use echo $ndcld['class'];

Sign up to request clarification or add additional context in comments.

Comments

0

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 ;)

2 Comments

Stop duplicating answers. (also 'class' -/- "class", see SQL query)
@Kenyanke I'm okay with the "" '' part... but - dublicateing answers? Where? I was writing this answer while the other one was posted. Also, an answer here should actually contain some explanation. The other one doesn't provide any, even tho its a good answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.