Jump to content

Can I do this in one query?


aebstract

Recommended Posts

I'm needing to update a column in my database, basically I have two tables:

 

participants:

id regid cr

 

registrations:

id class

 

The id columns are unique int values. The regid = registrations.id

I need to update the cr record for every row where the regid's class = "whatever".

This would be a piece of cake for me if I was just grabbing information, but I'm not so sure about updating the field.

Link to comment
https://forums.phpfreaks.com/topic/198430-can-i-do-this-in-one-query/
Share on other sites

mysql_query("UPDATE participants SET participants.cr = 'ql' JOIN registrations ON registrations.id = participants.regid WHERE registrations.class = '$_GET[class]' && participants.eventid = '$_GET[event]'")
or die(mysql_error());

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN registrations ON registrations.id = participants.regid WHERE registrations.' at line 1

 

 

So that I'm not just asking for it to be written for me. I will be working on this code.

mysql_query("UPDATE participants t1 JOIN registrations t2 ON (t1.regid = t2.id) SET cr = 'ql' WHERE class = '$_GET[class]' && eventid = '$_GET[event]'") or die(mysql_error());

 

Currently look like this, getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

If I remove the single quotes from the FROM section, I get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10.5 && eventid = 2' at line 1

 

When you remove the '' around ql I get:

Unknown column 'ql' in 'field list'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.