Reputation: 66
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:
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
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
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