PDO data
The younger brother encapsulates a function, there are three graphs, I want to take fetch () to the data to do While loop, but there is a dead loop, $roomName is a value
Solving
Reply to discussion (solution)
Your getlistroom called the Fetchdata and returned his results
and Fetchdata executes SQL queries every time.
Fetchdata always returns the first record of the query to the result, unless there is an error or no result found
So it's not possible to use the return value of Fetchdata as the judgment of the loop termination.
You should use Fetchall to return the result set array in the Fetchdata method
Then use the array method to show the result
Thank you, the problem has been solved. But there is a little doubt that you mean that the Fetch method can only be called directly in the loop, but there is no way to encapsulate the fetch.
You can package the fetch, but not like you!
For example, Fetchdata ($sql) is intended to execute SQL instructions and return results
The result may be one or more. So only fetch can not meet the requirements, to use Fetchall
In actual work, there are only a few query results, such as obtaining records, checking whether the user is registered, etc.
You can then define a Fetchrow method that returns only one row with fetch
I see, thanks!