I have a PHP page that is supposed to read and display all of the lines in a MySQL table. The page itself works fine, but the displayed results do not match what is actually in the table. If I browse the table using PHPMyAdmin, the newly added lines are shown. But if I go to the PHP page, these newly added results do not appear, even after refreshing. It is not until a few hours later that the lines are finally displayed by the PHP page.
I've already tried adding
header("Cache-Control: no-cache");
and
header("Pragma: no-cache");
but that didn't seem to help.
I'm relatively new to PHP and MySQL, but not to front end/database integration (I used to use ASP and MS SQL). But I've never seen anything like this. Any help would be greatly appreciated.
Delayed MySQL Results When Using PHP
Moderator: General Moderators
Wierd problem. Try using the following and see if that gives you more ideas:
Code: Select all
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");Here's the code I'm using to connect, as well as my SQL query:
$db_link = mysql_connect("[hostname]", "[username]", "[password]") or die("There was a problem connecting to the database.");
$status = mysql_select_db("[database]", $db_link);
if ($status) {
$sql_query= "SELECT * FROM tblSubprofile ORDER BY ID DESC";
$result = mysql_query($sql_query, $db_link);
$row = mysql_fetch_row($result);
$rowsReturned = mysql_num_rows($result);
$db_link = mysql_connect("[hostname]", "[username]", "[password]") or die("There was a problem connecting to the database.");
$status = mysql_select_db("[database]", $db_link);
if ($status) {
$sql_query= "SELECT * FROM tblSubprofile ORDER BY ID DESC";
$result = mysql_query($sql_query, $db_link);
$row = mysql_fetch_row($result);
$rowsReturned = mysql_num_rows($result);
Code: Select all
$status = mysql_close($db_link);