Jump to content

Recommended Posts

I'm struggling to get a cross join query working in my script.

 

At the moment I have 2 tables in a mysql database - merchants and vouchers. The relationship is each merchant has many vouchers i.e. one to many.

 

The fields of the merchant table are:-

 

merchant_id (Primary Key), merchant name

 

and the fields in the vouchers table are:-

 

voucher_id (Primary Key), merchant_id (Foreign key from the merchants table to signify which merchant the voucher is related to), voucher_name

 

I'm trying to implement a feature which once the user clicks a certain letter all vouchers that belong to any merchants whose merchant_name begins with the clicked letter will be shown but I can't seem to get it to work with the following query and am unsure as to where I'm going wrong:-

 

SELECT m.merchant_name, v.* FROM merchants AS m CROSS JOIN vouchers AS v USING(merchant_id) WHERE m.merchant_name like '$letter%'

 

$letter is a vriable that stores the letter that was clicked by the user.

 

Can anyone suggest anything? Thanks for the help in advance  :)

Link to comment
https://forums.phpfreaks.com/topic/221215-need-help-with-a-cross-join-query/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.