I need some help here, I have a search based upon 5 fields across 2 tables
Client ID (contract.client_id and client.client_id)
Last Name (client.clientl)
Contract Number (contract.contractnum)
Style (contract.style)
Designer Initials (contract.desinit)
If I use this php code
$query = "SELECT * FROM client,contract WHERE client.client_id = contract.client_id";
$result = mysql_query($query) or die("Try again");
it correctly joins the two tables and displays all of the results, however, I cannot figure out how to only display results based on the keyword search. If I search only by Last Name it returns all of the records in the contract table and the same for the other 4 fields.
Where do I go next ?...
here is what I have so far, but I know it is not correct:
$query = "SELECT FROM client,contract WHERE client.client_id = contract.client_id";
/$first_one = 1;
if($client_id != "") {
if($first_one == 1) {
$query = "$query WHERE";
$first_one = 0;
$query = "$query client_id LIKE '%$client_id%'";
}
else {
$query = "$query AND client_id LIKE '%$client_id%'";
}
}
if($clientl != "") {
if($first_one == 1) {
$query = "$query WHERE";
$first_one = 0;
$query = "$query clientl LIKE '%$clientl%'";
}
else {
$query = "$query AND clientl LIKE '%$clientl%'";
}
}
if($contract_num != "") {
if($first_one == 1) {
$query = "$query WHERE";
$first_one = 0;
$query = "$query contract_num LIKE '%$contract_num%'";
}
else {
$query = "$query AND contract_num LIKE '%$contract_num%'";
}
}
if($style != "") {
if($first_one == 1) {
$query = "$query WHERE";
$first_one = 0;
$query = "$query style LIKE '%$style%'";
}
else {
$query = "$query AND style LIKE '%$style%'";
}
}
if($desinit != "") {
if($first_one == 1) {
$query = "$query WHERE";
$first_one = 0;
$query = "$query desinit LIKE '%$desinit%'";
}
else {
$query = "$query AND desinit LIKE '%$desinit%'";
}
}
*/
$result = mysql_query($query) or die("Try again");