Read data from mysqli_fetch_array like a multidimensional array?

前端 未结 3 1834
执念已碎
执念已碎 2021-01-23 23:58

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

3条回答
  •  被撕碎了的回忆
    2021-01-24 00:07

    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.

提交回复
热议问题