You are here:  » Query custom fields from another table

Support Forum



Query custom fields from another table

Submitted by chrisst1 on Thu, 2012-03-01 10:22 in

Morning David

I'm trying to query two custom fields from the feeds table to include extra merchant info into the merchants AtoZ output. Is this possible to do as I only seem to get the same info from 1 merchant for all merchants rather than corresponding info foreach.

Chris

Submitted by support on Thu, 2012-03-01 10:46

Hi Chris,

The Merchant A-Z is a combination of merchants.php and the "generic" html/atoz.php module which is also used by the Category and Brand A-Z index pages.

One way to plumb extra information in on a generic basis would be to first edit html/atoz.php and look for the following code at line 58:

    print "</p>";

(this is the closing tag of each item) ...and REPLACE with:

    if (isset($item["info"])) print $item["info"];
    print "</p>";

The next step is to load $item["info"] with the content required in merchants.php. Look for the following code at line 14:

    $item["name"] = $product["merchant"];

So to select, for example user_field1 and user_field2 from the feeds table for that merchant, you could REPLACE the above with:

    $item["name"] = $product["merchant"];
    $sql = "SELECT user_field1,user_field2 FROM `".$config_databaseTablePrefix."feeds` WHERE merchant='".database_safe($product["merchant"])."'";
    database_querySelect($sql,$rows2);
    $item["info"] = $rows2[0]["user_field1"]." ".$rows2[0]["user_field2"];

That would then create a string comprising user_field [space] user_field2 to be displayed as the $item["info"] value...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Thu, 2012-03-01 16:50

Hi David

Thanks for that pointer, I was placing it in the A-Z and missing the row2 etc etc. Had to alter above slightly to make it work: Needed ; on end of the sql= line and rows[2][0] to rows2[0], don't know whether thats right to do or not.

$sql = "SELECT merchant_description,merchant_link_url FROM `".$config_databaseTablePrefix."feeds` WHERE merchant='".database_safe($product["merchant"])."'";

database_querySelect($sql,$rows2);

$item["info"] = $rows2[0]["merchant_description"]." ".$rows2[0]["merchant_link_url"];

Chris

Submitted by support on Fri, 2012-03-02 09:05

Spot on Chris!

Corrections incorporated above.

Cheers,
David.
--
PriceTapestry.com