close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLi Search Question (Aliases)

Thread began 2/07/2019 10:37 am by Dave Buchholz | Last modified 2/11/2019 12:31 pm by Ray Borduin | 24 views | 4 replies |

Dave BuchholzBeta Tester

MySQLi Search Question (Aliases)

I have a situation where I am pulling all the available colors for a product into the query and I need to include that alias in the search, my query looks something like this:

SELECT p.*, (SELECT GROUP_CONCAT(StandardColor) FROM tbl_products WHERE tbl_products.RootModelNumber = p.RootModelNumber) AS AvailableColors FROM tbl_products AS p etc.



but I get a error Unknown column 'AvailableColors' in 'where clause', I understand that this is a MySQL issue but I wondered if there was any way to get this to work in the search SB?

My search code looks like so:

$searchrsDataSet_1->setSearch(array("type"=>"List", "comparison"=>"Includes", "join"=>"AND"), array("AvailableColors"), "s", "color");
Sign in to reply to this post

Ray BorduinWebAssist

Could you use the query:

SELECT p.*, GROUP_CONCAT(StandardColor) AS AvailableColors FROM tbl_products AS p LEFT OUTER JOIN tbl_products ON tbl_products.RootModelNumber = p.RootModelNumber GROUP BY p.ProductID


and then use the search:

php:
$searchrsDataSet_1->setSearch(array("type"=>"List", "comparison"=>"Includes", "join"=>"AND"), array("tbl_products.StandardColor"), "s", "color");
Sign in to reply to this post

Dave BuchholzBeta Tester

Thanks Ray, unfortunately that gives me duplicate results on the colors because of the left join so I have hand coded a dynamic HAVING clause for the time being that seems to work

Sign in to reply to this post

Ray BorduinWebAssist

The GROUP BY statement should prevent the multiples... but I'm glad you found a solution that works for you. HAVING is quite a bit slower, but if you don't have too large of a database it shouldn't matter much.

Sign in to reply to this post

Dave BuchholzBeta Tester

Ray,
Have come back to this today and the issue is that I am grouping by RootModelNumber on the original query not by id so the outer join is pulling all the results. At most the query returns a couple of hundred results and I am paginating so at most 20 per page so it shouldn't be to bad.

UPDATE: I just discovered I can use the keyword DISTINCT within GROUP_CONCAT I had no idea I could do that, this makes it altogether possible now.

2nd UPDATE: although that solves my 1st issue it now removes the other colours when filtering which isn't what I want so back to the HAVING clause again

Thanks

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

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.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...