There’s no documentation for getRow, getRecordCount, or makeArray. I want to query a table and if it returns anything, increment a value, otherwise create an entry. I thought I had it working earlier but discovered that it always created a new entry, so clearly I don’t know what I’m doing.
Please, please, please, please someone just show me how to do this. I’m all for figuring things out for myself, but I can’t devote days to trial and error and I’m too clueless about PHP and MySQL in general to know what I should be doing.
In steps, how do I:
1) when user submits form check a specified table for a row where the values match those submitted by the user.
2) if a matching row exists, add 1 to a field called ct
3) if it doesn’t exist, create it and add a field called ct with a value of 1
#3 is the only one I can get to work.
Please, how do I do the rest of it?
I’ve tried almost everything, looked everywhere, and still haven’t a clue. Below is what I thought was the solution. It wasn’t.
-
☆ A M B ☆
- 24,524 Posts
If it works, it’s the MODx way!
You could use $modx->db->select(), but the parameter list is a bit arcane, and it all boils down to just being a wrapper for PHP’s mysql_query() anyway, so it doesn’t make that much difference.
To be honest, I often revert to using bare PHP mysql_whatever() function calls just to avoid the extra overhead of the MODx wrapper functions. They are primarily to make it trivial to add support for other database engines by creating a new dbapi file, but usually I’m not overly concerned about it; at least not for my own custom usage.