micky1955 Posted December 8, 2006 Share Posted December 8, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/ Share on other sites More sharing options...
artacus Posted December 8, 2006 Share Posted December 8, 2006 If you've got to refresh to see updates then yes its a caching issue. Try <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> in the head of your document and see if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-137194 Share on other sites More sharing options...
micky1955 Posted December 8, 2006 Author Share Posted December 8, 2006 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 -    </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] Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-137235 Share on other sites More sharing options...
jsladek Posted December 8, 2006 Share Posted December 8, 2006 Seemed to work fine for me...Maybe you have to clear your cache now that you have added that line and start your browser fresh.-John Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-137256 Share on other sites More sharing options...
btherl Posted December 8, 2006 Share Posted December 8, 2006 Another way to avoid caching is to add a dummy argument to your scripts. If your script is always called with "×tamp=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. Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-137268 Share on other sites More sharing options...
micky1955 Posted December 14, 2006 Author Share Posted December 14, 2006 Thanks for the replies peoplecould anyone please tell me how to [color=red]clear the cache [/color] or use [color=red]"×tamp=113768465"[/color] ?Micky. Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-140770 Share on other sites More sharing options...
JasonLewis Posted December 14, 2006 Share Posted December 14, 2006 to clear your cache, depending on your browser you have to go to Tools > Options and look for Clear Cache. I think in firefox you just have to go to Tools > Clear Private Data then select Cache and hit OK. IE may be different. Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-140780 Share on other sites More sharing options...
micky1955 Posted December 14, 2006 Author Share Posted December 14, 2006 Thanks ProjectFear.but is there any way to force the browser to [color=green]clear its cache[/color] by programming?Micky. Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-140804 Share on other sites More sharing options...
irken Posted December 14, 2006 Share Posted December 14, 2006 [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.htmlI will quote Jerdo from the above page.[quote]Before you output any HTML data put this in your scriptHeader("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] Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-140807 Share on other sites More sharing options...
micky1955 Posted December 14, 2006 Author Share Posted December 14, 2006 ;Dmany thanks irken,just tried your solution and problem appears to be solved! Quote Link to comment https://forums.phpfreaks.com/topic/29858-php-mysql-caching-problem-resolved-many-thanks-to-forum-helpers/#findComment-140817 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.