0

I am trying to retrieve 4 rows and I expected that It should display all 4 rows but it's only displaying the first row. This is the code I am using

$coquery = "Select distinct coName from avgcarcompany";
$crun = mysqli_query($con,$coquery);

$arrey = mysqli_fetch_assoc($crun);

print_r($arrey); 
2
  • What are the values of coName in your database? Commented May 30, 2020 at 9:33
  • Why do you expect four rows when you fetch only one? Commented May 30, 2020 at 9:37

1 Answer 1

2

If you want to get all rows from the result set then you need to fetch all. Right now you are fetching only one.

To fetch all rows use fetch_all()

$coquery = "Select distinct coName from avgcarcompany";
$crun = $con->query($coquery);

$arrey = $crun->fetch_all(MYSQLI_ASSOC)

print_r($arrey);
Sign up to request clarification or add additional context in comments.

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.