partiz
partiz

Reputation: 1216

how can I get row number via php/mysqli

id  state
1     1
2     0
5     1
4     0
7     1

I want first remove all state=0 form my result. and then return row number of target record.

for example for id='7' it must return me 3

how can I do it with mysqli/php?

this is false but something like this:

  function getLogs($itime = 0,$count = null)
    {
        $conn = $this->connectDB();
        $sql = "SELECT num_rows() FROM Content Where id='22' and  $state=0 ORDER BY id ASC";
        $rows = mysqli_fetch_all($conn->query($sql), MYSQLI_ASSOC);
        $this->disconnectDB($conn);
        return num_rows();
    }

Upvotes: 0

Views: 1135

Answers (1)

dstudeba
dstudeba

Reputation: 9038

This is probably simpler and you can replace 22 with a variable.

SELECT COUNT(id) FROM Content WHERE id <= 22 AND state != 0

In your example you put 22 in quotes, but your id isn't a string is it? Plus in addition to the comment above about $state = 0, it should be state not $state

Upvotes: 2

Related Questions