I'm creating this search function with PHP, javascript and mysql.
This code is working like it should. I type in some data in a a html search box, which sends the %keyword% to this PHP function, which returns the data as I want.
$query = "SELECT id,fornavn,efternavn,adresse,postnr,city,tlf,kon,email,fodselsdag FROM kunde WHERE email LIKE '%$keyword%' OR fornavn LIKE '%$keyword%'";
$result = mysqli_query($dbc,$query);
if($result){
if(mysqli_affected_rows($dbc)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
listings($row['fornavn'],$row['efternavn'], $row['email'],$row['adresse'],$row['tlf'],$row['postnr'],$row['city'],$row['fodselsdag'],$row['id'],$bartype);
}
I have another TABLE where the id from the SQL above is stored in relation to another ID. The table looks like this:
Table name: vip
Colmns: id, brugerid, barid
Now I want to be customize the SQL in the code above, so it only picks data that also has a relation in the vip table.
I do it this way:
SELECT *, kunde.id as kundeid FROM kunde,vip WHERE vip.brugerid = kunde.id AND vip.barid =1 AND email LIKE '%$keyword%' OR fornavn LIKE '%$keyword%';
Actually whenever I add more than one table, the php code stops working.. any idea why this is happening? And how I can achieve this?
Any help will be very appreciated