chromedude
chromedude

Reputation: 4302

How do you convert the result of a MySQL query into an integer in PHP?

I tried changing the result of a MySQL query to an integer with intval(), but I got an error saying it could not be changed to an int. Why I want to do this is to obtain the value of one of the fields in the database, minus one from it, and update the field with the new value. How would you do this with PHP?

Upvotes: 1

Views: 199

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52372

You don't need to do it in PHP. Subtract one in the UPDATE query itself.

UPDATE table SET column = column - 1

Don't forget a WHERE clause if this is only supposed to update specific rows.

Upvotes: 2

Related Questions