I am using a mysqli 'select where' query to return one row from a database that includes 4 items that I want to use in an html page (to display an image, title, description and alt text). The row is selected based on the unique title.
Currently I am using a fetch_assoc to get the data and then using a while loop to go through the results to build an array of the result. I then echo the html and array items to the page. This works fine.
However in this case, as I know there will only be one row returned and it would seem better to only echo the array items into the page html, rather than echo the array items and html together as part of the while loop.
However I tried to echo the array items outside of the while loop and they didn't display.
Hopefully that makes sense?
so my question is:
- is fetch-assoc the best method to get this one row of data from the database?
- are the array items available outside the while loop and if so how do I reference them?
Many thanks in advance