[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Recordset Sort Problem - Need to Add another Parameter

Asked by golena in PHP and Databases, JScript

I received this great solution to a recordset sort problem I was having.  I now need to add this form to another page where I need to an additional parameter of 'merchant'.  I thought I could simply add the parameter into the query but it's not working.

The original recordset sort query - this part works:

$sortby_rsProductsDiscount = "ASC";
if (isset($_GET['sort'])) {
  $sortby_rsProductsDiscount = (get_magic_quotes_gpc()) ? $_GET['sort'] : addslashes($_GET['sort']);
}
$orderby_rsProductsDiscount = "price";
if (isset($_GET['order'])) {
  $orderby_rsProductsDiscount = (get_magic_quotes_gpc()) ? $_GET['order'] : addslashes($_GET['order']);
}
$colname2_rsProductsDiscount = "1";
if (isset($_GET['subcategory'])) {
  $colname2_rsProductsDiscount = (get_magic_quotes_gpc()) ? $_GET['subcategory'] : addslashes($_GET['subcategory']);
}


mysql_select_db($database_golena_IDBdb, $golena_IDBdb);
if( isset($_REQUEST['OrderBy']) && !empty($_REQUEST['OrderBy']) )
        $query_rsProductsDiscount = sprintf("SELECT ((IDBdb.retail_price-IDBdb.price)/IDBdb.retail_price) AS discount, IDBdb.name, IDBdb.shortDescription, IDBdb.merchant_display, IDBdb.retail_price, IDBdb.price, IDBdb.url, IDBdb.thumbnail, IDBdb.productID, IDBdb.category, IDBdb.category_display, IDBdb.subcategory, IDBdb.subcategory_display, IDBdb.merchant FROM IDBdb WHERE (((IDBdb.subcategory)='%s')) ORDER BY %s", $colname2_rsProductsDiscount,$_REQUEST['OrderBy']);
else
        $query_rsProductsDiscount = sprintf("SELECT ((IDBdb.retail_price-IDBdb.price)/IDBdb.retail_price) AS discount, IDBdb.name, IDBdb.shortDescription, IDBdb.merchant_display, IDBdb.retail_price, IDBdb.price, IDBdb.url, IDBdb.thumbnail, IDBdb.productID, IDBdb.category, IDBdb.category_display, IDBdb.subcategory, IDBdb.subcategory_display, IDBdb.merchant FROM IDBdb WHERE (((IDBdb.subcategory)='%s')) ORDER BY %s %s", $colname2_rsProductsDiscount,$orderby_rsProductsDiscount,$sortby_rsProductsDiscount);
 
$query_limit_rsProductsDiscount = sprintf("%s LIMIT %d, %d", $query_rsProductsDiscount, $startRow_rsProductsDiscount, $maxRows_rsProductsDiscount);
$rsProductsDiscount = mysql_query($query_limit_rsProductsDiscount, $golena_IDBdb) or die(mysql_error());
$row_rsProductsDiscount = mysql_fetch_assoc($rsProductsDiscount);
 
if (isset($_GET['totalRows_rsProductsDiscount'])) {
  $totalRows_rsProductsDiscount = $_GET['totalRows_rsProductsDiscount'];
} else {
  $all_rsProductsDiscount = mysql_query($query_rsProductsDiscount);
  $totalRows_rsProductsDiscount = mysql_num_rows($all_rsProductsDiscount);
}
$totalPages_rsProductsDiscount = ceil($totalRows_rsProductsDiscount/$maxRows_rsProductsDiscount)-1;


***Problem Below***
Now I tried adding an additional parameter - 'merchant' to the query - but I am getting the following error:  "Warning: sprintf() [function.sprintf]: Too few arguments in /home/golena/public_html/thefrugaldesigner.com/viewproducts_m.php on line 120
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 'LIMIT 0, 10' at line 1"

Here is the query I modified with the additional merchant parameter - this is not working.


$colname_rsProducts = "1";
if (isset($_GET['merchant'])) {
  $colname_rsProducts = (get_magic_quotes_gpc()) ? $_GET['merchant'] : addslashes($_GET['merchant']);
}
$sortby_rsProducts = "ASC";
if (isset($_GET['sort'])) {
  $sortby_rsProducts = (get_magic_quotes_gpc()) ? $_GET['sort'] : addslashes($_GET['sort']);
}
$orderby_rsProducts = "price";
if (isset($_GET['order'])) {
  $orderby_rsProducts = (get_magic_quotes_gpc()) ? $_GET['order'] : addslashes($_GET['order']);
}
$colname2_rsProducts = "1";
if (isset($_GET['subcategory'])) {
  $colname2_rsProducts = (get_magic_quotes_gpc()) ? $_GET['subcategory'] : addslashes($_GET['subcategory']);
}


mysql_select_db($database_golena_IDBdb, $golena_IDBdb);
if( isset($_REQUEST['OrderBy']) && !empty($_REQUEST['OrderBy']) )
        $query_rsProducts = sprintf("SELECT ((IDBdb.retail_price-IDBdb.price)/IDBdb.retail_price) AS discount, IDBdb.name, IDBdb.shortDescription, IDBdb.merchant_display, IDBdb.retail_price, IDBdb.price, IDBdb.url, IDBdb.thumbnail, IDBdb.productID, IDBdb.category, IDBdb.category_display, IDBdb.subcategory, IDBdb.subcategory_display, IDBdb.merchant FROM IDBdb WHERE (((IDBdb.subcategory)='%s')) AND (((IDBdb.merchant)='%s')) ORDER BY %s", $colname2_rsProducts,$_REQUEST['OrderBy']);
else
        $query_rsProducts = sprintf("SELECT ((IDBdb.retail_price-IDBdb.price)/IDBdb.retail_price) AS discount, IDBdb.name, IDBdb.shortDescription, IDBdb.merchant_display, IDBdb.retail_price, IDBdb.price, IDBdb.url, IDBdb.thumbnail, IDBdb.productID, IDBdb.category, IDBdb.category_display, IDBdb.subcategory, IDBdb.subcategory_display, IDBdb.merchant FROM IDBdb WHERE (((IDBdb.subcategory)='%s')) AND (((IDBdb.merchant)='%s')) ORDER BY %s %s", $colname2_rsProducts,$orderby_rsProducts,$sortby_rsProducts);
 
$query_limit_rsProducts = sprintf("%s LIMIT %d, %d", $query_rsProducts, $startRow_rsProducts, $maxRows_rsProducts);
$rsProducts = mysql_query($query_limit_rsProducts, $golena_IDBdb) or die(mysql_error());
$row_rsProducts = mysql_fetch_assoc($rsProducts);
 
if (isset($_GET['totalRows_rsProducts'])) {
  $totalRows_rsProducts = $_GET['totalRows_rsProducts'];
} else {
  $all_rsProducts = mysql_query($query_rsProducts);
  $totalRows_rsProducts = mysql_num_rows($all_rsProducts);
}
$totalPages_rsProducts = ceil($totalRows_rsProducts/$maxRows_rsProducts)-1;



Thank you
Related Solutions: Recordset Sort Problem
[+][-]07/05/09 06:20 PM, ID: 24781936Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP and Databases, JScript
Sign Up Now!
Solution Provided By: cxr
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_Related_20080208