dongye9991 2016-06-05 17:31
浏览 79
已采纳

如何从PHP中的数据库中获取单个数字[重复]

This question already has an answer here:

I need to echo the number 1 or 0 whatever the database has in that cell. I cant seem to get it to work. What am I doing wrong people of the internet?

Picture of the database

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testfp";
$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
$bob = mysql_query($sql);
echo $bob;
?>
</div>
  • 写回答

1条回答 默认 最新

  • dttphb59319 2016-06-05 17:43
    关注

    You can not use mysql and mysqli together. So you can try the following code (using mysqli only, since mysql is deprecated) :

    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "testfp";
    $conn = new mysqli($servername, $username, $password, $dbname);
    //Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    $sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
    $result = $conn->query($sql);
    if($result->num_rows>0)
    {
        while($row = $result->fetch_assoc()) {
            echo $row["hookup"];
        }
    }
    else
    {
        echo "No results found!";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度