filtering by different table
Hi Ray
In the attached page, how would I get the recordset Products to filter based on a different table 'productcategories' using the column 'CatPeramlink'?
Cheers
Jamie
Hi Ray
In the attached page, how would I get the recordset Products to filter based on a different table 'productcategories' using the column 'CatPeramlink'?
Cheers
Jamie
I'm afraid I don't really understand your question. You are mixing terms in a way that makes it hard for me to follow. How do I filter a Recorset based on a different table? That sentence doesn't make sense to me.
Do you mean based on a different Recordset?
If you filter a Recordset, that recordset has to have a SQL statement that includes any tables you would filter in it. You can't filter a Recodset with a value from a table that the recordset doesn't have included in the recordset.
I'm not sure what you are doing, but the answer is to either add a join to the Recordset so that it has the table and columns you want to filter by, or to create another recordset to get the values you need and use that recordset to filter the next one based in its returned value.
ok, am struggling to explain it......
righy, the source page has a list of links which list out categories from a recordset (eg domain.co.uk/type/monthly-disposable where the last part is generated by the CatPermalink column in the productcategories table
When you click on the link, you get taken through to a page which, at the moment, lists all products. However, I want to filter the product results based on the category that is used in the URL (in the example the column CatPermalink - in my example monthly-disposable, but it could be another such as daily-disposable, its entirely dependent on whats in the tabel.
On the page I attached in my first post, the products are being listed by recordset 'Products' but I dont know how to then filter the results based on the URL monthly-disposable (or whatever has been created in the URL on the source page witht the CatPermalink column from the productcategories table.
Hope that perhaps explains a bit better ? :S
Jamie
I think you would do a join in the recordset to join in the Categories table and then you could filter that based on the url parameter generated by the url.
OK, so I have got
<?php
$Products = new WA_MySQLi_RS("Products",$DBConnection,0);
$Products->setQuery("SELECT products.*, productcategories.* FROM products INNER JOIN productcategories ON products.ProductCategoryID = productcategories.CategoryID WHERE products.ProductLive = 1 ORDER BY products.ProductOrder ASC");
$Products->execute();
?>
Not sure how I now filter by CatPermlink based on the url
Cheers
Usually your .htaccess file will translate the url into a URL parameter and then you would add the filter to the SQL statement using the $_GET parameter.
How would I structure the statement on that basis?
You would add the parameter to your WHERE clause. You might end up with:
<?php
$Products = new WA_MySQLi_RS("Products",$DBConnection,0);
$Products->setQuery("SELECT products.*, productcategories.* FROM products INNER JOIN productcategories ON products.ProductCategoryID = productcategories.CategoryID WHERE products.ProductLive = 1 AND ProductCategory = ? ORDER BY products.ProductOrder ASC");
$Products->bindParam("s","".($_GET['CatPermlink']) ."", "-1");
$Products->execute();
?>
thanks Ray. thats giving me an sql error which I believe is probably due to the highlighted reference here: http://prntscr.com/7g8gvp
should that be from the products or productcategories table?
I have tried replacing it with CategoryName (from productcategories) and also tried with ProductCategoryID from products but, although there is no error, no results are displayed.
Unfortunately I don't know what is in your .htaccess folder or what your exact database structure is, so I can't say what the issue is at this point.
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.