Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按id号mysql获取记录_Php_Mysql - Fatal编程技术网

Php 按id号mysql获取记录

Php 按id号mysql获取记录,php,mysql,Php,Mysql,这是我的数据库结构 id userid 1 x 2 xx 3 xxx 4 xx 我想用php显示第3行。仅按行号显示用户ID 结果应该是: xxx 试试这个 select userid from table where id=3 只需使用这个查询 SELECT userid FROM table WHERE id=3 这应该行得通 <?php $connection = new mysqli("localhost", "db_username",

这是我的数据库结构

id   userid
1    x
2    xx
3    xxx
4    xx
我想用php显示第3行。仅按行号显示用户ID

结果应该是:

xxx
试试这个

select userid from table where id=3
只需使用这个查询

SELECT userid FROM table WHERE id=3
这应该行得通

<?php
    $connection = new mysqli("localhost", "db_username", "db_password", "db_name");
    $result = mysqli_query($connection, "SELECT * FROM `table_name` WHERE `id` = '3' LIMIT 1");
    $record = mysqli_fetch_object($result);
    echo $record->userid;
?>
看看这里的答案和sqlfiddle:

mysql:

php:


从id=3的表格中选择userid
@user3371310,看看我的答案;
SELECT id, userid 
FROM t 
WHERE id=3;
$result = mysqli_query($connection, "SELECT id,userid FROM t WHERE id = 3");