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. For reference, why here Since Your solution is definitely to use $ 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); }
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.
$ 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 .
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
Post a Comment