Ishmam Haque Bhuiyan
Ishmam Haque Bhuiyan

Reputation: 66

mysql get row number from table where a column value is equal to a specific value

I have a table where results of modeltest are given in a column in descending order. Now I want to get the row number of a specific row. Here is the example table:

enter image description here

So when i will search a with userid=44, it should return 3. Again when i will search with userid=11, it should return 4. How can I do this ? If anyone could kindly help me out.

Upvotes: 0

Views: 428

Answers (2)

buildok
buildok

Reputation: 785

for example:

$stmt = PDO::prepare('SELECT id FROM table WHERE userid = ?');
$userId = 44;

$stmt->execute([$userId]);
$result = $stmt->fetch(PDO::FETCH_OBJ);

echo $result->id;

http://php.net/manual/en/book.pdo.php

Upvotes: 1

JParkinson1991
JParkinson1991

Reputation: 1286

A simple where clause will achieve this.

SELECT id FROM table WHERE userid = 44

Swap table and userid value to whatever is needed.

Hope this helps

Upvotes: 0

Related Questions