dppfxf909679 2016-08-19 02:38
浏览 38
已采纳

将MySQLi查询结果存储在PHP变量中

All i want to do is to store the name of the guest that is on the A1 seat in a PHP variable named "resulted".

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'test';
$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


$resulted = mysqli_query("SELECT name FROM guests WHERE seat='A1');

echo $resulted;
?>

I know this is totally wrong but I don't know how i shoud do it....

  • 写回答

2条回答 默认 最新

  • dongxu8533486 2016-08-19 03:08
    关注

    There is some issue in your code. I have fetched associative array amd print gust name.

        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass = 'root';
        $dbname = 'test';
        $con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
        if ($con->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }
    
    
        $resulted = mysqli_query($conn, "SELECT name FROM guest WHERE seat='A1'");
        if(mysqli_num_rows($resulted) > 0) {
         $row = mysqli_fetch_assoc($resulted);
          print_r($row['name']);
        }
    
    
        // Free result set
        mysqli_free_result($resulted);
    
        mysqli_close($con);
    
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致