mySQL query isn't working (I think it's the where clause)

I’m trying to query something that is sorted by a where clause then I wanted to order the data by a specific value (I’m implementing a sort dropdown on a table). This isn’t working though and I can’t figure out why.

SELECT * FROM reservation_form_results WHERE campaign_id = $campaignId ORDER BY FIELD(status, '$sortValue')

It works without the WHERE clause, but I need that in order to sort the data first.

What you posted is not SQL. The query should look like this:

So the problem is somewhere in creating that query.

1 Like

Assuming that $campaignId is a PHP variable, you’d have to wrap that in single quotes: '$campaignId'