Keweqqwe Keweqqwe - 5 months ago 8
SQL Question

mysql query 3 tables php output name instead id

Need some help.
I have got 3 tables. klients, klientwithservice, service.



table klients
id | klientrnd
---------
1 | 11231231
2 | 22222222

table service
id | servicename
---------
1 | Repair laptop
2 | Repair pc

table klientwithservice
id | klientrnd | serviceid
-------------------------------
1 | 11231231 | 1
2 | 11231231 | 2
3 | 22222222 | 1
4 | 22222222 | 2





I need to output
SERVICENAME
instead
ID
.
My sql query is:



SELECT serviceid FROM klientwithservice WHERE '$pole8' = `klientrnd`





Where
$pole8 = klientrnd
exactly person on which page i placed.

Answer

for this you need to JOIN two table

use below query

SELECT s.servicename FROM klientwithservice as kws
JOIN service as s ON s.id = kws.serviceid
WHERE  `klientrnd` = '$pole8'