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
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.

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.