botcha Posted January 19, 2012 Share Posted January 19, 2012 HI , newbie here ! I have 4 tables ( event, price, vehicle, town) I want to select from a database when a user chooses the town, event and number of passengers (which I have got the form working ok) when displaying results I can get it to retrieve the $town and $event details fine,I just need the vehicleID column in the vehicle table to match the price.vehicleID when it is equal to $pax $calc = (" SELECT* FROM price, vehicle WHERE price.townID = $town AND price.eventID = $event AND $pax == vehicle.passenger AND price.vehicleID = vehicle.vehicleID "); if you have a look at www.hirealimo.com.au you will see what m trying to do. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/ Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 there's no == operator in mysql? $calc = (" SELECT* FROM price, vehicle WHERE price.townID = $town AND price.eventID = $event AND $pax == vehicle.passenger AND price.vehicleID = vehicle.vehicleID "); Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309150 Share on other sites More sharing options...
botcha Posted January 19, 2012 Author Share Posted January 19, 2012 thanks for the quick response, ive removed the == now i get: Unknown column 'vehicle.passenger' in 'where clause' the only other way i can think of doing it is to run a SELECT query to retrive the vehicle.vehicleID (based on the input from the number of passengers selected) then run my other query again. Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309153 Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 do you have passenger column in your vehicle table? Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309154 Share on other sites More sharing options...
botcha Posted January 19, 2012 Author Share Posted January 19, 2012 price table priceID vehicleID townID eventID price 1 1 1 1 444 2 2 1 2 555 3 1 1 3 345 4 1 2 1 457 5 4 2 2 127 6 1 2 3 333 7 4 3 1 880 8 1 3 1 1500 9 2 3 1 900 vehicle table vehicleID vehtype passengers description 1 limo 14 stretched territor\ 2 limo 9 stretched fairlane 3 sedan 4 fairlane sedan 4 limo 12 Ford FG stretch limo this is what i have so far: $calc = ("SELECT * FROM price WHERE price.townID = $town AND price.eventID = $event INNER JOIN vehicle ON price.vehicleID = vehicle.vehicleID WHERE vehicle.passengers >= $pax "); my goal is to show each vehicle option as a result, based upon the TOWN they choose, the EVENT (eg wedding) and number of pax price.vehicleID is a foreign key from vehicle.vehicleID Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309429 Share on other sites More sharing options...
botcha Posted January 19, 2012 Author Share Posted January 19, 2012 link is hirealimo.com.au/code1.php Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309430 Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2012 Share Posted January 19, 2012 You're getting the unknown column error because the field name is passengers. Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309431 Share on other sites More sharing options...
botcha Posted January 19, 2012 Author Share Posted January 19, 2012 Thanks Pikachu2000, but i dont understand? can you hit refresh on this: hirealimo.com.au/code1.php is it ok to use 2 WHERE 's in one select query? Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309434 Share on other sites More sharing options...
El Chupacodra Posted January 20, 2012 Share Posted January 20, 2012 Sure you can, you use WHERE a=b AND c=d. What Pikachu says is that your column is called passengers and the query in your first post says passenger. Look at the last letter - they're not the same. Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309470 Share on other sites More sharing options...
botcha Posted January 20, 2012 Author Share Posted January 20, 2012 ok cool, thanks, i fixed that earlier on. I have fixed my problem using the USING thingo: SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 works great !! Quote Link to comment https://forums.phpfreaks.com/topic/255343-using-select-to-get-id-from-table/#findComment-1309486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.