I have a query in php that has an offset in it. I want the offset value to be a variable but I am not sure how to do so. This is my query but it comes up as an error.

$query = "SELECT * 
FROM comments 
    `commenter_username` IN (" . join(',', $list) . ") OR
    `Number` IN (" . join(',', $list) . ") 
ORDER BY `comment_id` DESC
LIMIT 1 OFFSET $offsetNumber";

What is wrong with this?

Member Avatar


LIMIT $offset, 1

If you just want the one record. Records start on record 0 ($offset = 0).

commenter_username IN (" . join(',', $list) . ")

You need ' around each list item:

commenter_username IN ('" . implode("','", $list) . "')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.