Jump to content

Problems with SQL Helper Function


mcpacific

Recommended Posts

I'm working on a module, and I need to do an SELECT QUERY with an INNER JOIN. Here is what I have:

 

$table = "tblcustomfieldsvalues";
$fields = "fieldid,fieldname";
$where = array(
	"relid"=>array("sqltype"=>"LIKE","value"=>$params['serviceid']),
);
$sort = "fieldid";
$sortorder = "ASC";
$limits = "0,2";
$join = "tblcustomfields ON tblcustomfields.id=tblcustomfieldsvalues.fieldid";
$result = select_query($table,$fields,$where,$sort,$sortorder,$limits,$join);

 

There are two custom fields for this product, and their values occupy two rows in the tblcustomfieldsvalues table. This query should result in two records, with fieldid (from tblcustomfieldvalues) and fieldname (from tblcustomfields) for each. However, $result always comes up null.

 

Anyone out there have any ideas?

Link to comment
Share on other sites

Ok, for anyone who's interested, I figured it out. I think the problem stems from the field "relid" being present in both tables. Therefore, I added the table name to the $where variable as follows:

 

   $where = array( 
       "tblcustomfieldsvalues.relid"=>array("sqltype"=>"LIKE","value"=>$params['serviceid']), 
   );

 

It seems to have done the trick. :)

Link to comment
Share on other sites

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.   Paste as plain text instead

  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

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated