Jump to content

Join in update - for postgres


bayswater

Recommended Posts

Hi experts,

 

I have this update, which DOESN'T work when my page hooks up to a postgres database:

 

pg_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE c.category = '".$vist."' AND c.visible = '0' AND c.category <> '0'");

 

Is there a conflict with the JOIN in an update when it comes to postgres, or...?

 

 

My identical code for Mysql is working fine:

 

mysql_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE c.category = '".$vist."' AND c.visible = '0' AND c.category <> '0'"); 

Link to comment
Share on other sites

well, the JOIN is completely unnecessary and that might be the problem with postgres. and since you already require category = '$vist', there is no need to add the condition that category != 0

 

 

$sql = "UPDATE ".$prefix."course SET visible = '1' WHERE category = '".$vist."' AND visible = '0'";

Link to comment
Share on other sites

well, the JOIN is completely unnecessary and that might be the problem with postgres. and since you already require category = '$vist', there is no need to add the condition that category != 0

 

 

$sql = "UPDATE ".$prefix."course SET visible = '1' WHERE category = '".$vist."' AND visible = '0'";

Ah, yes, I get the category !=0, but I now realize that I pasted the wrong SQL :wtf: I have 2 almost identical and in this second - I NEED a join (I guess?) to the categories table:

 

mysql_query("UPDATE ".$prefix."course c INNER JOIN ".$prefix."course_categories cat ON c.category = cat.id SET c.visible = '1' WHERE cat.path like '%/".$vist."/%' AND c.visible = '0' AND c.category <> '0'");

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.