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? Link to comment https://forums.phpfreaks.com/topic/295155-help-on-joining-two-mysql-tables-using-pdo/ Share on other sites More sharing options...
Barand Posted March 7, 2015 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 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 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
Archived
This topic is now archived and is closed to further replies.