ThiloSavage Posted September 25, 2007 Share Posted September 25, 2007 I have a table.. five rows by 30/31 days. Each cell has a status level which it gets from a database. My current script works, but it queries the database to see the status of each cell So that means every time a month is displayed, it makes about 150 queries to the database. Is that bad/unacceptable? It's currently like this- $rows = array('1','2','3','4','5'); foreach ($rows as $row) { for ($day=0;$day<$DaysinMonth;$day++) { $res = mysql_fetch_array(mysql_query("SELECT ... WHERE `row` = $row AND `day` = $day)); if ($res['level'] == 1) { do something } else if ($res['level'] == 2) { do something else } } } Is there a better way to structure this to cut down on queries? Or is it not an issue? Quote Link to comment https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/ Share on other sites More sharing options...
jaymc Posted September 25, 2007 Share Posted September 25, 2007 Yeh... What is the purposes of the table What data is stored and with that data what do you want to output Maybe a screenshot of your database 'browse' in phpmyadmin or something Then we can help you redesign the database or structure the query Quote Link to comment https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/#findComment-355029 Share on other sites More sharing options...
mpharo Posted September 25, 2007 Share Posted September 25, 2007 I would do it all in one query and then put it into an array and then extract the results from the array. Quote Link to comment https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/#findComment-355042 Share on other sites More sharing options...
ThiloSavage Posted September 26, 2007 Author Share Posted September 26, 2007 How do I make a MySQL query for a date range? Like, if I want all rows for April 2007, is this right? mysql_query("SELECT * FROM `table` WHERE `date` > '20070400' AND `DATE < `20070500`"); ?? Quote Link to comment https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/#findComment-355722 Share on other sites More sharing options...
mpharo Posted September 26, 2007 Share Posted September 26, 2007 that really depends on your format of your date field. You have the general idea, but just use the format that you have in the field to get the proper results. Quote Link to comment https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/#findComment-355810 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.