rvdveen27 Posted July 15, 2015 Share Posted July 15, 2015 Hello people. I'm having some issues with the convoy page once again after I had to split the first query. Currently it selects the right convoy information, but at the signups it shows the signups from the first convoy. Now my question, is it possible to get the information from the first query and using it in a later query? Currently I have this set up: First query: $query = " SELECT cv.date as 'date' ,cv.comment as 'comment' ,cv.id as 'convoyid' FROM convoy cv ORDER BY id DESC LIMIT 0, 1 "; try { $stmt = $db->prepare($query); $result = $stmt->execute(); } catch(PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } $rows = $stmt->fetchAll(); $count = $stmt->rowcount(); ?> Second query: $query = " SELECT u.username ,cvsu.id FROM convoysignup cvsu INNER JOIN users u ON u.id = cvsu.username WHERE cvsu.id = :convoyid "; $query_params = array( ':convoyid'=> $rows[0]['convoyid'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute(); } catch(PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } $rows3 = $stmt->fetchAll(); $count = $stmt->rowcount(); ?> Which gives me: Failed to run query: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound I'm mainly talking about if $query_params = array( ':convoyid'=> $rows[0]['convoyid'] is actually correct and an okay solution to solve this issue? Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/ Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 Where do you use $query_params? Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516436 Share on other sites More sharing options...
rvdveen27 Posted July 15, 2015 Author Share Posted July 15, 2015 Where do you use $query_params? Line 203, second query. Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516440 Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 No. That's where you define it. Where do you USE it? Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516441 Share on other sites More sharing options...
scootstah Posted July 15, 2015 Share Posted July 15, 2015 That's where you are setting it, but you are not using it. You need to give the parameters to the execute() method. $result = $stmt->execute($query_params); Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516442 Share on other sites More sharing options...
rvdveen27 Posted July 15, 2015 Author Share Posted July 15, 2015 That's where you are setting it, but you are not using it. You need to give the parameters to the execute() method. $result = $stmt->execute($query_params); Another lesson learned today Thanks! Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.