Jump to content

PHP & Mysql caching problem - RESOLVED! Many thanks to forum helpers!


micky1955

Recommended Posts

am learning PHP, slowly, but it takes a while at my age!

have written code for database maintenance - add, edit, delete & search.

all works fine apart from one problem - for instance after adding, deleting or editing a record the code to read & display the data shows the updates ok. 

When running that same piece of code again it does not show the updates unless the page is refreshed.

i am confused as to why this happens!

data reading code is below.

is this something to do with caching?

if so why does data display correctly the first time?

any help will be much appreciated.

[code]
if( $searchtext=="") :
             // NO SEARCH REQUESTED - SELECT ALL
$result = mysql_query("SELECT ID , Title , Genre, Year FROM filmdata ORDER by `Title`");
else:
$result = mysql_query("SELECT * FROM `filmdata` WHERE Genre LIKE '%$searchtext%' order by `Title`");
$searchtext="";
ENDIF;
$numfilms=mysql_num_rows($result);
if (!$result)
{
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}[/code]
Link to comment
Share on other sites

thanks for the reply Artacus.

tried that - works when adding a record.

still have prob with amending - if you amend again record that was recently amended form will show old data although new was shown when displaying all records - weird init?

url is [url=http://www.ddm.org.uk/case.php]http://www.ddm.org.uk/case.php [/url]  if anyone would please have a look - only test data used so do what you like with it.

code for the editing form shown below

[code]<?php
$sql = mysql_query("SELECT * FROM `filmdata` WHERE `ID` = $editfilm");
$row = mysql_fetch_array($sql);

$existyear=$row[Year];
$existtitle=$row[Title];
$existgenre=$row[Genre];
$filmid = $editfilm;
?>
<table class="search">
<tr>
<td class="search">
<FORM ACTION="<?php echo($php_SELF); ?>" METHOD=GET>
Amend Data - &nbsp&nbsp
</td>
<td class="search">
<INPUT TYPE=TEXT NAME="newyear" VALUE="<?php echo($existyear); ?>" size="4" maxlength="4">
</td>
<td class="search">
<INPUT TYPE=TEXT NAME="newtitle" VALUE="<?php echo($existtitle); ?>" size="40" maxlength="40" >
</td>
<td class="search">
<INPUT TYPE=TEXT NAME="newgenre" VALUE="<?php echo($existgenre); ?>" size="40" maxlength="40">
</td>
<td class="search">

<INPUT TYPE=SUBMIT NAME="submitfilm" VALUE="CANCEL">
</td>
<td class="search">
<input type=hidden name="editformdone" value=1>
<input type=hidden name="delid" value=<?php echo $filmid ?>; >
<INPUT TYPE=SUBMIT NAME="submitfilm" VALUE="SUBMIT">
</td>
</FORM>
</tr>
</table>
[/code]
Link to comment
Share on other sites

Another way to avoid caching is to add a dummy argument to your scripts.  If your script is always called with "&timestamp=113768465", which changes every second, then even the most zealous cache can't use output from a previous call to the script that had a different timestamp.
Link to comment
Share on other sites

[quote author=micky1955 link=topic=117780.msg484475#msg484475 date=1166060101]
Thanks ProjectFear.

but is there any way to force the browser to [color=green]clear its cache[/color] by programming?

Micky.
[/quote]

I don't think you can directly force the user to clear the entire cache (that would be mean), but you can force the browser to clear the cache for your specific page. I've googled a page for you: http://www.phpbuilder.com/board/archive/index.php/t-10206989.html

I will quote Jerdo from the above page.

[quote]
Before you output any HTML data put this in your script

Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");

I've used these on quite a few pages to keep AOL's proxies from caching pages to make AOL look faster and it seems to work.
[/quote]
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.