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");