Jump to content

managing when queries are run...


mkosmosports

Recommended Posts

Hey all,

Ive recently restructured some of my code, so that query results get put into multidimensional arrays and then displayed using loops. Now what Id like to do is set these queries to run only when there are new entries present in the table. Im thinking I should learn about using sessions and then have each query run once per session, then always run a small query checking for a new PK, and then run the main query only if there is another a new PK present in the table. Is this a correct way of thinking? Has anyone else successfully implemented similar script before?

All ideas, suggestions, insults welcome..... ;D

mkosmosports
Link to comment
Share on other sites

Sure.

This is a soccer news/stats website. The queries ran are queries that retrieve stats. numbers, names, etc.
Ive redone the code so that most queries put its results into arrays. The purpose of that is so there are less queries being ran, and if there are no new relevant entries, just use whats in the existing array (So Im hoping the array can exist until the user has finished the session maybe? How long does an array stay in memory anyways?) Here is an example query that retrieves teams playing in a specific league.

$result3 = @mysql_query("SELECT GT.START_DATE as sdate, GT.END_DATE as edate, T.ID as teamid, T.QUICK_NAME as quickname, T.OFFICIAL_NAME as fullname, T.COUNTRY as country FROM sf_group_team GT, sf_team T WHERE GT.START_DATE BETWEEN '$seasonbeg-06-20' AND '$view-03-10' AND GT.GROUP_ID = $group AND GT.TEAM_ID = T.ID");
if (!$result3 )
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}

Heres the array which will contain the necessary results.

while ( $row = mysql_fetch_array($result3, MYSQL_ASSOC) )
{
$result3arr[] = array('quickname' => $row['quickname'], 'teamid' => $row['teamid'], 'country' => $row['country'], 'sdate' => $row['sdate'],'edate' => $row['edate']);
}

Now I only want the query to run again only if there are new PK entries in that table. (Id have to write another query to check that, mysql_query would do, but maybe there is a specific mysql function for that in php.) If there are no new PK entries in that table I want the array to be used to show the necessary data.

Does that help businessman?

Thanks.
Link to comment
Share on other sites

Ok, an array itself just depends

If you are dymanically creating arrays, they stay in memory for the duration fo the script with no statesaving.

For instance, if you made an array based on someone's actions, or something, it will clear when they close, the browser.  Actually it will clear when they change pages.  If a database, get, post, session, cookie or something isn't making the data stick, the array is cleared everytime they load a new page.

Other than that, I don't still understand enough to help beyond that.
Link to comment
Share on other sites

By what it sounded you are trying to limit the amount of queries that can be ran.

There really isn't a point.  The only way I can think, is database the ip, and increment a number everytime someone run's a query.  THen when they reach a certain amoutn stop there future queries for a specified amount of time.

In the end you have used extra queries, and defeated the whole purpose anyway.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.