I have three tables:

collections
[clientID][isbn]

books
[title][isbn][author]

clients
[cliendID][firstName][lastName]

I am making a seach functon on php. The function will search the clientID and display the name (from the clients table) and what book that client has (fro collections table). What should I do for the query?

$query = "select * from database.collections where clientID like '%".$searchterm."%'";

This is what I have right now. It's able to display the entered clientID and the ISBNs.

Member Avatar for LastMitch

@chuyauchi

This is what I have right now. It's able to display the entered clientID and the ISBNs.

You should have post this in PHP section rather than database. The reason why is that you didn't give much detail how your seach functon on php works.

Base on the query you provided:

$query = "select * from database.collections where clientID like '%".$searchterm."%'";

I came up with this:

$sql="SELECT cliendID.collections, cliendID.clients, isbn.collections, isbn.books, firstName, lastName, title, author FROM database.collections, database.books, database.clients WHERE cliendID.collections = cliendID.clients LIKE '%".$searchterm."%' AND isbn.collections = isbn.books LIKE '%".$searchterm."%' AND firstName LIKE '%".$searchterm."%' OR lastName LIKE '%".$searchterm."%' OR title LIKE '%".$searchterm."%' OR author LIKE '%".$searchterm."%'"; 

I don't have a db to test it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.