MasAdam
MasAdam

Reputation: 453

SQL LIKE from multiple table

I want to create a search bar that could list the product name and product owner.

Table ITEM consist of pID (FK from PROFILE), itemName, and itemDate

Table PROFILE consist of pID, firstName, and lastName

Initially, the '%$Keurig%' supposed to be '%$searchtag%' (the value passed from search bar).

However since it didn't show anything, I decided to use '%$Keurig%' to find out what happened.

Turns out, it didn't show anything as well.

Here's what I wrote:

SELECT I.itemName,P.firstName,P.lastName
      FROM `ITEM` I, `PROFILE` P
      WHERE I.pID=P.pID AND I.itemName LIKE '%$Keurig%'

It supposed to print a user name John because he is the only one that owns Keurig.

Anybody knows what I did wrong? Thank you.

Upvotes: 1

Views: 66

Answers (1)

Vinie
Vinie

Reputation: 2993

Remove $ from '%$Keurig%'. Try this

SELECT I.itemName,P.firstName,P.lastName
  FROM `ITEM` I, `PROFILE` P
  WHERE I.pID=P.pID AND I.itemName LIKE '%Keurig%'

With $searchtag try somthing like this

$sql = "SELECT I.itemName,P.firstName,P.lastName
  FROM `ITEM` I, `PROFILE` P
  WHERE I.pID=P.pID AND I.itemName LIKE '%".$searchtag."%'";

Upvotes: 1

Related Questions