Jump to content

Cut down on DB queries


ThiloSavage

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/70642-cut-down-on-db-queries/
Share on other sites

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 :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.