-2

I'm only getting the first row from database

<?php require('testconfig.php') ?>
<html>
    <head>
    </head>
    <body>
    <?php 
        $sql="SELECT * FROM item ";
        $sqlll=mysqli_query($conn,$sql) or die ("cant fetch data");
        $result=mysqli_fetch_assoc($sqlll);
    ?>
<table border='1'>
<tr>
<td>r.no</td>
<td>name</td>
<td>prices</td>
</tr>
<?php 
    while ($row=mysqli_fetch_assoc($sqlll)) 
    {
        echo "<tr>";
        echo "<td>".$result['RNO']."</td>";
        echo "<td>".$result['ITEMNAME']."</td>";
        echo "<td>".$result['PRICE']."</td>"; 
        echo "</tr>";
        echo "<br/>";
    }
?>
</table>
</body>
</html>

What I supposed to get is that show all result from query on html table by looping.

this is my table name=test

-------------------------------------
r.no  |itemname |price |leftinstore |
-------------------------------------
1     |ball     |98.45 |4           |
-------------------------------------
2     |book     |90    |7           |
-------------------------------------
3     |food     |68.98 |4           |
-------------------------------------
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 4
    Mind changing the CAPS to lowercase or Camel Case please? It's considered as shouting. – Funk Forty Niner Jun 15 '17 at 13:02
  • `$result` inside the while loop should be `$row` instead. If you change this, everything should work. Actually you're only seeing one result because you're printing from $result, and you're not looping trough. – Twinfriends Jun 15 '17 at 13:03
  • Did you escape twitter https://twitter.com/php_ceo? – PeeHaa Jun 15 '17 at 13:04
  • btw, this is a typo error. and error reporting would have told you about it. This also looks like a repost from another (probably deleted) account which I distinctively remember from not so long ago; a day or two as a matter of fact. – Funk Forty Niner Jun 15 '17 at 13:05
  • Why are you fetching the first row outside the while loop? – Tobias F. Jun 15 '17 at 13:05
  • @TWINFRIENDS OOPS !!!! sorry....@Twinfriend... for shouting at you again i would like to thank you for your automatic answer it feels like you knew my question before i get to ask .......any way i'm going to check it.... – iwant2bhacker Jun 15 '17 at 13:07
  • @iwant2bhacker No problem. :) Glad that I could help. – Twinfriends Jun 16 '17 at 06:20

1 Answers1

0

Change the name of your while-loop variable to result and everything should work fine. Before you weren't looping trough $result, you looped $row and used $result in your loop.

<?php require('testconfig.php') ?>
    <html>
        <head>
        </head>
    <body>
    <?php 
    $sql="SELECT * FROM item ";
    $sqlll=mysqli_query($conn,$sql) or die ("cant fetch data");
    ?>
    <table border='1'>
    <tr>
    <td>r.no</td>
    <td>name</td>
    <td>prices</td>
    </tr>
    <?php 
        while ($result=mysqli_fetch_assoc($sqlll)) 
        {
    echo "<tr>";
    echo "<td>".$result['RNO']."</td>";
    echo "<td>".$result['ITEMNAME']."</td>";
    echo "<td>".$result['PRICE']."</td>"; 
    echo "</tr>";
    echo "<br/>";
    }
    ?>
    </table>
    </body>
    </html>
Twinfriends
  • 1,972
  • 1
  • 14
  • 34