Landslyde Posted March 7, 2015 Share Posted March 7, 2015 $id = $_POST['view']; // Pass this to see which attendee was selected in the Selection box options $stmt = $db->prepare('SELECT a.fname, a.lname, h.amount, h.subsidy, h.last_payment, h.amount_paid, h.balance FROM attendees As a INNER JOIN history AS h ON a.attendeeid = :id AND h.attendeeid = :id'); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetchAll(); I know the last part of the query is wrong, the ON a.attendee = :id, etc. But how do I pass $id off to both a.attendeeid and h.attendeid and make it work? I need to be able to somehow make it ON a.attendeeid = h.attendeeid'); ...but that makes them devoid of $id. I've also tried $stmt = $db->prepare('SELECT a.fname, a.lname, h.amount, h.subsidy, h.last_payment, h.amount_paid, h.balance FROM attendees As a INNER JOIN history AS h WHERE a.attendeeid = :id AND h.attendeeid = :id'); $stmt->bindValue(':id', $id, PDO::PARAM_INT); but that offers nothing either. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/295155-help-on-joining-two-mysql-tables-using-pdo/ Share on other sites More sharing options...
Solution Barand Posted March 7, 2015 Solution Share Posted March 7, 2015 FROM attendees As a INNER JOIN history AS h ON a.attendeeid = h.attendeeid That tells it to match rows from a with those rows from h where the attendeeid values match Now add a WHERE clause to specify what value you want to select WHERE a.attendeeid = :id EG SELECT a.fname, a.lname, h.amount, h.subsidy, h.last_payment, h.amount_paid, h.balance FROM attendees As a INNER JOIN history AS h ON a.attendeeid = h.attendeeid WHERE a.attendeeid = :id Quote Link to comment https://forums.phpfreaks.com/topic/295155-help-on-joining-two-mysql-tables-using-pdo/#findComment-1507826 Share on other sites More sharing options...
Landslyde Posted March 7, 2015 Author Share Posted March 7, 2015 Thanks, Barand. I tried every way but the right way on that one. Much appreciated. Think I'm gonna call it a day now Quote Link to comment https://forums.phpfreaks.com/topic/295155-help-on-joining-two-mysql-tables-using-pdo/#findComment-1507827 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.