0

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?

4 Answers 4

2

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);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

try this:

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

Comments

0

You have to fetch the result using loop :

$b = mysql_fetch_array($query)

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

Comments

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.