When I use mysqli_fetch_array()
I get an array, but how do I read the values? Is a While-Loop the only option, or can I pick any value from a row and column like a
Your question suggests that your goal is just to get a single value. If that is the case, you should limit your query to only return what you're looking for rather than getting everything and then finding what you want in the results with PHP.
For the column, specify the one column you want instead of using *
, (SELECT one_column FROM your_table)
and for the row, either use a WHERE
clause to select a specific id (provided that is defined on your table) or use a LIMIT
clause to select a specific row number from the result set. Then you won't have to fetch in a loop or fetch all. Your query result (if it's successful) will just have one row with one column, and you can fetch once and get your value.
Granted, if you're going to need to do this repeatedly (i.e. in a loop), it isn't the best approach.