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

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条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分