jasonc Posted October 13, 2021 Share Posted October 13, 2021 CREATE TABLE `info` ( `id` int(11) NOT NULL, `section` text NOT NULL, `content` text NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; The table below is what I have setup but having issues accessing the content based on the section needed. I have tried... $result['sectionname']['content'] but nothing shows. What is the correct way to access each content using the section. without doing it one query for each one. Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/ Share on other sites More sharing options...
ginerjm Posted October 13, 2021 Share Posted October 13, 2021 (edited) You title makes no sense and your code is nothing at all. What are you trying to learn??? Are you simply asking how to read an entire table? Very simple to do. But do you really need all of the columns in all of the rows? As for getting the data "in to an array", well, that is basically how a query result is returned. One can simply do a fetchall to grab all the results in one swoop but most of the time one processes the query results by using a fetch and a loop to process each row. As for your create - you might want to use the varchar type instead of the text type. And do you really want to use the 'latin1' charset over the more usual 'utf8' one? As for your last question - you haven't shown us your query so kinda hard to help you with that. Although it sounds like you just need to use the order by clause. I have given you a lot to answer so I patiently await your thoughtful response. Edited October 13, 2021 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/#findComment-1590990 Share on other sites More sharing options...
jasonc Posted October 13, 2021 Author Share Posted October 13, 2021 Thank you I have taken the uft8 on board. It has been some years since I have coded. I am hoping to grab all the rows from the table, only 10 or so, then be able to read the results which ever 'content' column by using the 'section' Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/#findComment-1590992 Share on other sites More sharing options...
ginerjm Posted October 13, 2021 Share Posted October 13, 2021 Well you hope to grab the rows. And THEN you want to read the results? How about telling us what you want to accomplish instead of how you want to code it? Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/#findComment-1590994 Share on other sites More sharing options...
jasonc Posted October 13, 2021 Author Share Posted October 13, 2021 $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> Instead of accessing the DB twice only access once. Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/#findComment-1590996 Share on other sites More sharing options...
ginerjm Posted October 13, 2021 Share Posted October 13, 2021 You need to step back and speak in English about what you are trying to do. No code. Quote Link to comment https://forums.phpfreaks.com/topic/313976-how-to-ready-all-db-table-in-to-array/#findComment-1590997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.