X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Query help please... (https://forum.x-cart.com/showthread.php?t=50394)

mrerotic 10-27-2009 04:08 AM

Query help please...
 
How can I check to see if parentid = '1' for a product? I think my query below is wrong can someone please verify that this query should work?
PHP Code:

$test func_query("SELECT productid FROM $sql_tbl[products] WHERE product = '$p[product]'");
// Get category parentid to find section for product
$pcatquery "SELECT categoryid FROM $sql_tbl[products_categories] WHERE productid = '".$test."'";
$prodcatinfo func_query($pcatquery);
 
if (!empty(
$prodcatinfo)){
foreach (
$prodcatinfo as $pcat){
$getpquery func_query("SELECT parentid, category FROM $sql_tbl[categories] WHERE categoryid = '".$pcat['categoryid']."'");
foreach (
$getpquery as $getpcat){
if (
$getpcat['parentid'] != '0'){
if (
$getpcat['parentid'] == '1'){
$pcatsection "dvds";
}
}
}
}



rogue 10-27-2009 05:56 AM

Re: Query help please...
 
I suspect that you need more than you are asking for here. But here is a single query that will do what you want I think.

Code:


$result = func_query("
SELECT cats.parentid
FROM $sql_tbl[products] as prods,
    $sql_tbl[products_categories] as prod_cats, 
    $sql_tbl[categories] as cats
WHERE prods.product = '$p[product]' and
      cats.productid = prods.productid and
      prod_cats.categoryid = cats.categoryid and
      prod_cats.parentid = 1
")

if (count($result) == 1) {
  $pcatsection = 'dvds';
}


You should probably run the query from phpMyAdmin to make sure it does what you want.

Rick


All times are GMT -8. The time now is 06:06 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.