简体   繁体   中英

Get record by id number mysql

This is my database structure.

id   userid
1    x
2    xx
3    xxx
4    xx

I want to display row no. 3 in php. Only userid by row number.

Result should be :

xxx

尝试这个

select userid from table where id=3

只需使用此查询

SELECT userid FROM table WHERE id=3

This should work

<?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;
?>

look here this answer and sqlfiddle: http://sqlfiddle.com/#!2/f001f/2

mysql:

SELECT id, userid 
FROM t 
WHERE id=3;

php:

$result = mysqli_query($connection, "SELECT id,userid FROM t WHERE id = 3");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM