Jump to content
techker

Search from 1 Database linked to another..

Recommended Posts

Hey Guys im confused on this..

 

i have 2 tables

1 that is for the client that store the coupons and values

2 is the master list that  has all the coupons

So basically i show all the coupons from the master Databse and the members clicks add to his Album (Like a shopping cart)

 

So database members

MYID
UserID
CouponID    
DateIn    
Visible    
Precieux    
QTY_Visible    
QTY
CName    
Barcode    
Rebate    
Exp

Database Coupon_list

id
product_name    
product_desc    
product_code    
product_date_exp    
product_user    
product_image        
product_image_thumb    
product_status    
product_qty    
product_folder    
product_cat    rop    
product_type
product_month    
Recherche_Nom    
ImgType        
product_barcode    
master        
product_comp
product_rebate    
IsEditable    
 

SO i linked the both together and i need to have a search .this is what i did

 

  if(preg_match("/^[0-9- a-zA-Z]+/", $_POST['name'])){
      
  $name=$_POST['name'];


  $searchterms=preg_replace("/'/", "\'", $name);

  SELECT* FROM MyAlbum 
  INNER JOIN Coupon_list ON MyAlbum.CouponID=Coupon_list.id 
  WHERE MyAlbum.UserID = $Session 
  AND product_cat LIKE '%" . $searchterms .  "%'
  OR product_comp LIKE '%" . $searchterms ."%'  
  OR product_rebate LIKE '%" . $searchterms ."%' 
  OR id LIKE '%" . $searchterms ."%' 

But somehow i get all the Members results..not the members album...

 

i need to show the members album results not all the members

 

 

Share this post


Link to post
Share on other sites

Please use the right terminology. You are talking about tables, not databases. Calling them "databases" is going to get people confused.

If you want information from a third table then you must be selecting from that third table. It won't magically appear without that.

Share this post


Link to post
Share on other sites

sorry, i only need 2 tables and search in my first that links the second to view the coupons by id

Share this post


Link to post
Share on other sites

You have shown us the content of two tables

  • members
  • coupon_list

Your query uses two tables

  • MyAlbum
  • coupon_list

so I haven't a clue what you are really trying to do as your post makes no sense.

Share this post


Link to post
Share on other sites

ya i got it cause my AND was before the OR

 

$teamQuery3=mysqli_query($DBcon,"SELECT* FROM MyAlbum
    LEFT JOIN Coupon_list ON MyAlbum.CouponID =Coupon_list.id
    WHERE product_cat LIKE '%" . $searchterms .  "%'
    OR product_comp LIKE '%" . $searchterms ."%'
    OR product_rebate LIKE '%" . $searchterms ."%'
    OR MyAlbum.CouponID LIKE '%" . $searchterms ."%'
    AND MyAlbum.UserID = $Seesion");

 

 

cause i have a master table that conatains all the coupons. So the member scrolls all the coupons and if he has it he adds it to his album.

before i was duplicating the info in the members album..

 

now what i do is store the id of the master coupon in the MyAlbum database with the qty names....

 

 

 

Share this post


Link to post
Share on other sites

I have no idea what you just said.

 

However, when using a mix of AND and OR in a WHERE clause, use parentheses to define the logic. For example

A AND B OR C

Do you mean

(A AND B) OR C

or do you mean

A AND (B OR C)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.