dstt1818
2014-12-31 11:15
浏览 143
已采纳

PHP和mysql,SELECT查询返回null

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;
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongyigua4468 2014-12-31 11:34
    已采纳

    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;
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题