in reply to UPDATE ON DUPLICATE and sorting
I see that your insert fields and your update fields are the same set, except for "url". Perhaps "url" should be defined the primary key, instead of an auto-increment field. Without this, the "ON DUPLICATE KEY UPDATE" operation makes no sense and cannot be applied to the table.
You can make "url" the primary key while still having an auto-increment "row_num" field (or a "created_at" date/time field) that is not the primary key, and this can still be used to do the "order by" and "limit 10" that you want.
BTW, you really should be using placeholders for the values in the insert/update statement, and passing those variables as params to the "execute" call; if you use the same statement for more than one set of fields, and especially if the values are coming from outside your script (i.e. any "untrusted" source, like cgi params, environment variables, files, or other user input), placeholders are The Best Way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: UPDATE ON DUPLICATE and sorting
by coldfingertips (Pilgrim) on Feb 06, 2006 at 04:52 UTC | |
by graff (Chancellor) on Feb 06, 2006 at 05:14 UTC |