this is PHP code:
<?php
// header('Content-type: application/json');
header('Content-Type: text/html; charset=UTF-8');
$d=$_GET["userid"];
$servername = "*******";
$username = "***";
$password = "****";
$dbname = "*****";
$arr = array();
$My_Connection = mysql_connect ( $servername, $username , $password ) ;
if ( ! $My_Connection )
{
die( ' Could not connect : ' . mysql_error( ) ) ;
}
//pick data base
mysql_select_db ( $dbname, $My_Connection );
mysql_set_charset('utf8',$My_Connection);
$sql_tempcreate="CREATE TABLE tmp(id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,DID VARCHAR(20) NOT NULL)";
if(mysql_query($sql_tempcreate,$My_Connection))
{
$sql_convert="ALTER TABLE tmp CONVERT TO CHARACTER SET utf8";
mysql_query($sql_convert);
$sql_inserttotemp="INSERT INTO tmp (DID) SELECT DID FROM user WHERE 1 Order By HIGHSCORE DESC";
if(mysql_query($sql_inserttotemp,$My_Connection))
{
//***************************************** from here problem start
$sql_rank="SELECT * FROM `tmp` WHERE DID =".$d."";// |
$r=mysql_query($sql_rank,$My_Connection); // |
// |
$rank= $r; // V
}//******************************************************** to here
}
else
{
$rank= array("ERROR","ERROR");
}
$output = json_encode(array('top' => $arr,'rank' =>$rank));
echo ($output);
}
else
{
echo "there is an error :(";
}
mysql_query("DROP TABLE tmp",$My_Connection);
mysql_close($My_Connection);
?>
table tmp create successfully , data insert to tmp table successfully but "select query" return me null! actually $r is null i try (LIKE & =)but same result
what is wrong with this query?
EDIT:
i even change the query to:
$sql_rank="SELECT * FROM tmp WHERE DID=352136069213581"
and not working again :(
tanks
EDIT: correct answer:
tanks to gaurav kumar this is correct code :D
$sql_rank="SELECT * FROM `tmp` WHERE DID LIKE ".$d."";
$res=mysql_query($sql_rank,$My_Connection);
$r=mysql_fetch_assoc($res);
$rank= $r;