打印mysqli SELECT查询的结果 [英] Print the Result of a mysqli SELECT Query

查看:93
本文介绍了打印mysqli SELECT查询的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在数据库中搜索结果,并显示与该结果有关的所有列.我与数据库的连接工作正常,但是我不知道如何打印查询结果.

I am trying to search my database for a result, and display all the columns relating to that result. My connection to the database works fine, but I don't know how to print the result of my query.

我尝试以数组形式访问它,但是没有用.我想要的是能够在数据库中搜索用户名"TEST",并返回密码,电子邮件和用户名(以检查用户名是否存在).

I tried accessing it as an array, but it did not work. What I want is to be able to search the database for the username 'TEST', and to return the password, email and username (to check the username exists).

我当前的代码是

$user = mysqli_query($con,"SELECT * FROM user_list where username = '$username'");
print_r($user); 

$username是用户名.它返回

(
    [current_field] => 0
    [field_count] => 4
    [lengths] => 
    [num_rows] => 2
    [type] => 0
)

推荐答案

使用访存显示结果

     $result = mysqli_query($con,"SELECT * FROM user_list where username = '" . mysqli_real_escape_string($con, $username) . "'"); 
    while($row = mysqli_fetch_array($result))
     {
        print_r($row);
     } 

这篇关于打印mysqli SELECT查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆