MySQL Forums
Forum List  »  PHP

php mysql select query returning the old results although the table is updated with new records
Posted by: kiran devabattula
Date: May 29, 2015 08:27AM

Hello,
I have php function which uses mysql select query to get the customers list from customers table.
This function is called on a timer basis from java script.
and the customers table is updated from another page which does insert into customers table every time a new customer is logged in.

the problem is this select query returns the old results although a new customer is added to it


<?php
function getcustomers()
{
$servername = "localhost";
$username = "testuser";
$password = "testpwd";
$dbname = "customersdb";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
echo "connection error";
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT SQL_NO_CACHE username from customers";
$result = $conn->query($sql);
unset($userNameArray);
$userNameArray = array(); // make a new array to hold all your data
$userinfo = array();
$index = 0;
if ($result->num_rows > 0)
{
//echo $result->num_rows;
while($row = $result->fetch_assoc())
{
//echo $row['username']. "<br/>";
array_push($userNameArray , $row['username']);
}
}
else
{
echo "0 results";
}
$conn->close();
$arrlength = count($userNameArray );
for($x = 0; $x < $arrlength; $x++)
{
echo $userNameArray[$x]."<br/>";
}
}
?>


javascript code

var funccall=function()
{
var latestcustomers="<?php getcustomers(); ?>";
var splitcusotmers = latestcustomers.split("<br/>");
alert(splitcusotmers);
};

function step1 () {
setInterval(funccall, 3000);
}

Options: ReplyQuote


Subject
Written By
Posted
php mysql select query returning the old results although the table is updated with new records
May 29, 2015 08:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.