How to read results array based on content of column

I have an info database table with various things that will go on my pages, I have the editor scripts done, but when it comes to getting the info from the table to place on the pages I am querying the DB for them one by one for each section. How can I query the DB and get all of them (about 10 at present) and be able to read just the content for the section I need, without cycling through each row.

	$fetch = db_query($mysqli, "SELECT * FROM `info` WHERE `section` = 'openingtimes'");
	$result = $fetch->fetch_assoc();
	$openingtimes = $result['content'];
	$openingtimes = str_replace("\r\n", "
	<br>
	", $openingtimes);
	
	$fetch = db_query($mysqli, "SELECT * FROM `info` WHERE `section` = 'foodtimes'");
	$result = $fetch->fetch_assoc();
	$foodtimes = $result['content'];
	$foodtimes = str_replace("\r\n", "
	<br>
	", $foodtimes);
	?>
	<?php
	echo($openingtimes); ?><br><br><?php
	echo($foodtimes);?><br><br>

You would use a single query to get the data that you want, in the order that you want it (almost every SELECT query should have an ORDER BY … term.) Then, you would simply output the data the way you want when you loop over the result set from that single query.

Note: you should list the column(s) you are selecting, rather than use SELECT *. Don’t copy variables to other variables for nothing, just use the original variable. Php has a function to add
tags to any new-lines a value, see nl2br().

The example above is just one page some have many items to add to the pages.
I have been told that the result-set is an array already, so looking to use something that does not need me to query for each and every one, one at a time.
say
$array[‘foodtimes’][‘content’]

Sponsor our Newsletter | Privacy Policy | Terms of Service