1

I have a MySQL table called comments that contains a column called vz_comments and basically I want to show all the comments related to the character_id. However my current query only shows 1 comment but when I put the statement into phpmyadmin it shows all the comments.

$comments_query = $conn->query("SELECT vz_comments FROM comments WHERE character_id='$comment_id'");

$comments_array = $comments_query->fetch_array();

echo $comments_array['vz_comments'];
2
  • 5
    You are only fetching one row. If you want all rows, use fetch_all(). Commented Feb 6, 2016 at 12:15
  • $comments_array = $comments_query->fetch_all(MYSQLI_ASSOC) Commented Feb 6, 2016 at 12:21

1 Answer 1

2

fetch_array fetches a single row as an array of its columns (either numeric or associative, depending on the parameters. By default, MYSQLI_BOTH is used, retrieving an array with attributes of both styles.

To fetch the entire result in a single call, you should use fetch_all instead.

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.