PHP - basic select query returning only the first row of mysql database -


I'm running a phpMyAdmin query and it shows all the rows, but my query in php gives only the first line. $ result = $ mydb -> Query ("SELECT * music_sheet WHERE category = '" $ _ request ["submitter"]. "'"); Print (count ($ result)); // always returns 1 for $ ($ x = 0; $ x & lt; count ($ result); $ x ++) {$ row = mysqli_fetch_row ($ result); }

For reference, why here count () If the parameter is not an aggressive or is not an executable object with calculable interface, then 1 will be returned. An exception is, if array_or_countable [ parameter ] is NULL, then 0 will be returned.

Since $ result is resource (the object) that has been returned from your query, not an array that gives you your loop , Which returns the actual data out of the resource, count ($ resource) will return 1 .

Your solution is definitely to use mysqli_num_rows () . To retrieve data from this resource, you should do as you are doing, but it needs a loop, but mysqli_num_rows () to count () , Or other (more common) ways to loop through a result set, such as:

  while ($ row = mysqli_fetch_row ($ result)) {// do stuff}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -