Page 1 of 1

Obtain data from database using mysql

Posted: Tue Jul 08, 2014 2:29 am
by pallu0619
I am having this database sample, I am not able to post the pic but it contains many columns in which two columns are of 14_val and 11_val.
So now I have prepared two php files namely data1.php and data2.php.
The data1.php is as followed:

Code: Select all

<?php
header('content-type: application/json; charset=utf-8');
$con=mysql_connect('localhost','root','root');
mysql_select_db('wafms',$con);
$hsh = time();
if (isset($hsh))
    $table_n="sdata".floor($hsh/100000);
else
{
    $loc = mysql_query("SELECT MAX(numbr) from table_info;");
    $arlc = mysql_fetch_array($loc);
    $table_n="sdata".$arlc[0];
}
	
$select_query = " SELECT hash,l4_val FROM ".$table_n." ORDER BY hash DESC LIMIT 1 ";
$list = mysql_query($select_query);
$record = mysql_fetch_array($list);
$data1 = $record[0]*1000;
$data2 = $record[1];
if($data2==Null){
    $r = array(doubleval($data1),$data2);
}
else
    $r = array(doubleval($data1),doubleval($data2));
echo json_encode($r);
?>

& my data2.php is as followed:

Code: Select all

<?php
header('content-type: application/json; charset=utf-8');
$con=mysql_connect('localhost','root','root');
mysql_select_db('wafms',$con);
$hsh = time();
if (isset($hsh))
    $table_n="sdata".floor($hsh/100000);
else
{
    $loc = mysql_query("SELECT MAX(numbr) from table_info;");
    $arlc = mysql_fetch_array($loc);
    $table_n="sdata".$arlc[0];
}
	
$select_query = " SELECT hash,l1_val FROM ".$table_n." ORDER BY hash DESC LIMIT 1 ";
$list = mysql_query($select_query);
$record = mysql_fetch_array($list);
$data1 = $record[0]*1000;
$data2 = $record[1];
if($data2==Null){
    $r = array(doubleval($data1),$data2);
}
else
    $r = array(doubleval($data1),doubleval($data2));
echo json_encode($r);
?>
Now the problem is that the data1.php file returns the most recent data from the column 14_val as database updates itself. But the problem is that data2.php is not giving the most recent data in the same way from the column 11_val.

What can be the problem can anyone help me with this. It would be great . Thanks for your help in advance. It is urgent please.