user2523382
user2523382

Reputation: 23

mysql query does not showing multiple rows

my database sample is like this

database:test
table:test

id  name  password   message  active
1   test  testpass   testmsg   no
2   test2 testtest   testmsg2  no

and when i run sql query and show it in php it just gives one result. php part was,

$a=mysqli_query($con,"select name from test where active='no'");
$b=mysqli_fetch_array($a);
print_r($b);

and it showed only the first record

test

can anybody please suggest me,where I am doing wrong?

Upvotes: 0

Views: 68

Answers (4)

Rohitashv Singhal
Rohitashv Singhal

Reputation: 4557

You have to fetch the result using loop :

$b = mysql_fetch_array($query)

foreach($b as $b)
{
  echo $b[];
]

Upvotes: 0

rr-
rr-

Reputation: 14811

This is desired behavior of PHP. You should fetch the rows in loop, like this:

$result = mysqli_query($con,"select name from test where active='no'");
while ($row = mysqli_fetch_array($result))
{
    print_r($row);
}

Upvotes: 2

Daniel Robertus
Daniel Robertus

Reputation: 1102

try this:

echo "<pre>";
print_r($b);
echo "</pre>";

Upvotes: 0

bugwheels94
bugwheels94

Reputation: 31920

Use a while loop to iterate over all the records

$a=mysqli_query($con,"select name from test where active='no'");
while($b=mysqli_fetch_array($a))
print_r($b);

Upvotes: 2

Related Questions