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
https://forums.phpfreaks.com/topic/225837-join-in-update-for-postgres/
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'";

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'");

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.