glozinski
asked on
PHP Modification
I would like to have the category name appear on this page.
However I need to add a condition to the select statement to include the category name. I am a newbie to php....
SELECT *, coalesce((select ps4_productoptions.Groupin gID
FROM ps4_productoptions
WHERE ps4_productoptions.Product ID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE())
GROUP BY GroupingID
ORDER BY ProductName
However I need to add a condition to the select statement to include the category name. I am a newbie to php....
SELECT *, coalesce((select ps4_productoptions.Groupin
FROM ps4_productoptions
WHERE ps4_productoptions.Product
GROUP BY GroupingID
ORDER BY ProductName
We need to see you database structure to know where the 'category name' attribute is located i.e. what entity it's in, etc. Please provide that so we can help.
ASKER
Try this, please:
SELECT *, coalesce((select ps4_productoptions.Groupin gID
FROM ps4_productoptions
WHERE ps4_productoptions.Product ID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE())
LEFT JOIN ps4_categories ON ps4_productoptions.Product CategoryID = ps4_categories.CategoryID
GROUP BY GroupingID
ORDER BY ProductName
SELECT *, coalesce((select ps4_productoptions.Groupin
FROM ps4_productoptions
WHERE ps4_productoptions.Product
LEFT JOIN ps4_categories ON ps4_productoptions.Product
GROUP BY GroupingID
ORDER BY ProductName
No points for this, just a couple of comments.
You might enjoy this book:
http://www.sitepoint.com/books/phpmysql4/
Try to avoid SELECT * if you know the names of the columns you really want to SELECT. Your queries will always be faster.
Best regards, ~Ray
You might enjoy this book:
http://www.sitepoint.com/books/phpmysql4/
Try to avoid SELECT * if you know the names of the columns you really want to SELECT. Your queries will always be faster.
Best regards, ~Ray
ASKER
here is the error I received
[19-Sep-2011 14:14:07] PHP Warning: mysql_free_result(): 106 is not a valid MySQL result resource in /home/ps4/public_html/weba ssist/plug ins/catalo g/results_ grid.php on line 297
here is the bottom tag
<?php
mysql_free_result($WADAPro ducts);
if(isset($all_WADAProducts )) mysql_free_result($all_WAD AProducts) ;
if(isset($MaxMinPrice)) mysql_free_result($MaxMinP rice); line 297
if(isset($DefaultProd)) mysql_free_result($Default Prod);
?>
<?php
$maxRows_WADAProducts = 9;
$pageNum_WADAProducts = 0;
if (isset($_GET['pageNum_WADA Products'] )) {
$pageNum_WADAProducts = $_GET['pageNum_WADAProduct s'];
}
$startRow_WADAProducts = $pageNum_WADAProducts * $maxRows_WADAProducts;
mysql_select_db($database_ PowerStore Connection , $PowerStoreConnection);
$query_WADAProducts = "SELECT *, coalesce((select ps4_productoptions.Groupin gID FROM ps4_productoptions WHERE ps4_productoptions.Product ID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE()) LEFT JOIN ps4_categories ON ps4_productoptions.Product CategoryID = ps4_categories.CategoryID GROUP BY GroupingID ORDER BY ProductName ";
setQueryBuilderSource($que ry_WADAPro ducts,$WAD bSearch1,f alse);
$query_limit_WADAProducts = sprintf("%s LIMIT %d, %d", $query_WADAProducts, $startRow_WADAProducts, $maxRows_WADAProducts);
$WADAProducts = mysql_query($query_limit_W ADAProduct s, $PowerStoreConnection) or die(mysql_error());
$row_WADAProducts = mysql_fetch_assoc($WADAPro ducts);
if (isset($_GET['totalRows_WA DAProducts '])) {
$totalRows_WADAProducts = $_GET['totalRows_WADAProdu cts'];
} else {
$all_WADAProducts = mysql_query($query_WADAPro ducts);
$totalRows_WADAProducts = mysql_num_rows($all_WADAPr oducts);
}
$totalPages_WADAProducts = ceil($totalRows_WADAProduc ts/$maxRow s_WADAProd ucts)-1;
?>
Thank you
[19-Sep-2011 14:14:07] PHP Warning: mysql_free_result(): 106 is not a valid MySQL result resource in /home/ps4/public_html/weba
here is the bottom tag
<?php
mysql_free_result($WADAPro
if(isset($all_WADAProducts
if(isset($MaxMinPrice)) mysql_free_result($MaxMinP
if(isset($DefaultProd)) mysql_free_result($Default
?>
<?php
$maxRows_WADAProducts = 9;
$pageNum_WADAProducts = 0;
if (isset($_GET['pageNum_WADA
$pageNum_WADAProducts = $_GET['pageNum_WADAProduct
}
$startRow_WADAProducts = $pageNum_WADAProducts * $maxRows_WADAProducts;
mysql_select_db($database_
$query_WADAProducts = "SELECT *, coalesce((select ps4_productoptions.Groupin
setQueryBuilderSource($que
$query_limit_WADAProducts = sprintf("%s LIMIT %d, %d", $query_WADAProducts, $startRow_WADAProducts, $maxRows_WADAProducts);
$WADAProducts = mysql_query($query_limit_W
$row_WADAProducts = mysql_fetch_assoc($WADAPro
if (isset($_GET['totalRows_WA
$totalRows_WADAProducts = $_GET['totalRows_WADAProdu
} else {
$all_WADAProducts = mysql_query($query_WADAPro
$totalRows_WADAProducts = mysql_num_rows($all_WADAPr
}
$totalPages_WADAProducts = ceil($totalRows_WADAProduc
?>
Thank you
Not sure what the problem is, but try commenting out that line like so and run and again:
<?php
mysql_free_result($WADAProducts);
if(isset($all_WADAProducts)) mysql_free_result($all_WADAProducts);
//if(isset($MaxMinPrice)) mysql_free_result($MaxMinPrice); line 297
if(isset($DefaultProd)) mysql_free_result($DefaultProd);
?>
<?php
$maxRows_WADAProducts = 9;
$pageNum_WADAProducts = 0;
if (isset($_GET['pageNum_WADAProducts'])) {
$pageNum_WADAProducts = $_GET['pageNum_WADAProducts'];
}
$startRow_WADAProducts = $pageNum_WADAProducts * $maxRows_WADAProducts;
mysql_select_db($database_PowerStoreConnection, $PowerStoreConnection);
$query_WADAProducts = "SELECT *, coalesce((select ps4_productoptions.GroupingID FROM ps4_productoptions WHERE ps4_productoptions.ProductID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE()) LEFT JOIN ps4_categories ON ps4_productoptions.ProductCategoryID = ps4_categories.CategoryID GROUP BY GroupingID ORDER BY ProductName ";
setQueryBuilderSource($query_WADAProducts,$WADbSearch1,false);
$query_limit_WADAProducts = sprintf("%s LIMIT %d, %d", $query_WADAProducts, $startRow_WADAProducts, $maxRows_WADAProducts);
$WADAProducts = mysql_query($query_limit_WADAProducts, $PowerStoreConnection) or die(mysql_error());
$row_WADAProducts = mysql_fetch_assoc($WADAProducts);
if (isset($_GET['totalRows_WADAProducts'])) {
$totalRows_WADAProducts = $_GET['totalRows_WADAProducts'];
} else {
$all_WADAProducts = mysql_query($query_WADAProducts);
$totalRows_WADAProducts = mysql_num_rows($all_WADAProducts);
}
$totalPages_WADAProducts = ceil($totalRows_WADAProducts/$maxRows_WADAProducts)-1;
?>
ASKER
inserted this:
<?php
mysql_free_result($WADAPro ducts);
if(isset($all_WADAProducts )) mysql_free_result($all_WAD AProducts) ;
//if(isset($MaxMinPrice)) mysql_free_result($MaxMinP rice); line 297
if(isset($DefaultProd)) mysql_free_result($Default Prod);
?>
uploaded to http://65.254.54.66/~ps4/products_results.php?pageNum_WADAProducts=20&totalRows_WADAProducts=225&Search=0 I will leave for your to review if you wish
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN ps4_categories ON ps4_productoptions.Product CategoryID = ps4_categorie' at line 1
code from line 1-7
<?php require_once('../../../Con nections/P owerStoreC onnection. php'); ?>
<?php require_once("../../../WA_ Validation Toolkit/WA VT_Scripts _PHP.php") ; ?>
<?php require_once("../../../WA_ Validation Toolkit/WA VT_Validat edForm_PHP .php"); ?>
<?php
//WA Database Search Include
require_once("../../../WAD bSearch/He lperPHP.ph p");
?>
sorrry....
<?php
mysql_free_result($WADAPro
if(isset($all_WADAProducts
//if(isset($MaxMinPrice)) mysql_free_result($MaxMinP
if(isset($DefaultProd)) mysql_free_result($Default
?>
uploaded to http://65.254.54.66/~ps4/products_results.php?pageNum_WADAProducts=20&totalRows_WADAProducts=225&Search=0 I will leave for your to review if you wish
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN ps4_categories ON ps4_productoptions.Product
code from line 1-7
<?php require_once('../../../Con
<?php require_once("../../../WA_
<?php require_once("../../../WA_
<?php
//WA Database Search Include
require_once("../../../WAD
?>
sorrry....
Change your sql to this please:
SELECT *, coalesce((select ps4_productoptions.Groupin gID
FROM ps4_productoptions prod
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
WHERE ps4_productoptions.Product ID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE())
GROUP BY GroupingID
ORDER BY ProductName
It may be a problem with using the asterisk (like Ray said) when trying to access two tables.
SELECT *, coalesce((select ps4_productoptions.Groupin
FROM ps4_productoptions prod
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
WHERE ps4_productoptions.Product
GROUP BY GroupingID
ORDER BY ProductName
It may be a problem with using the asterisk (like Ray said) when trying to access two tables.
ASKER
okay still getting same error
however when uploading using cute ftp error page says this
[20-Sep-2011 13:47:53] PHP Warning: mysql_free_result(): 108 is not a valid MySQL result resource in /home/ps4/public_html/weba ssist/plug ins/catalo g/results_ grid.php on line 297
so here is this code
<?php if ($pageNum_WADAProducts > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_WADAPro ducts=%d%s ", $currentPage, max(0, $pageNum_WADAProducts - 1), $queryString_WADAProducts) ; ?>">Prev</a>
wow...
however when uploading using cute ftp error page says this
[20-Sep-2011 13:47:53] PHP Warning: mysql_free_result(): 108 is not a valid MySQL result resource in /home/ps4/public_html/weba
so here is this code
<?php if ($pageNum_WADAProducts > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_WADAPro
wow...
ASKER
ignore the cute ftp that corrected itself however, still having this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN ps4_categories ON ps4_productoptions.Product CategoryID = ps4_categorie' at line 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN ps4_categories ON ps4_productoptions.Product
Make sure to change the code to what I provided. Because, 'LEFT JOIN ps4_categories ON ps4_productoptions.Product CategoryID = ps4_categorie' at line 1' shouldn't exist, it should be replaced with:
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
So, your whole query should be:
SELECT *, coalesce((select ps4_productoptions.Groupin gID
FROM ps4_productoptions prod
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
WHERE ps4_productoptions.Product ID = ps4_products.ProductID limit 1),ps4_products.ProductID) AS GroupingID FROM ps4_products WHERE ProductLive = 1 AND (ProductStartDate IS NULL OR ProductStartDate <= CURDATE()) AND (ProductEndDate IS NULL OR ProductEndDate >= CURDATE())
GROUP BY GroupingID
ORDER BY ProductName
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
So, your whole query should be:
SELECT *, coalesce((select ps4_productoptions.Groupin
FROM ps4_productoptions prod
LEFT JOIN ps4_categories cat ON cat.CategoryID = prod.ProductCategoryID
WHERE ps4_productoptions.Product
GROUP BY GroupingID
ORDER BY ProductName
ASKER
this is the error i now get
Unknown column 'ps4_productoptions.Groupi ngID' in 'field list'
Unknown column 'ps4_productoptions.Groupi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
did not work