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? Quote 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? Quote 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. Quote 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? Quote Link to comment https://forums.phpfreaks.com/topic/297309-use-data-from-previous-query/#findComment-1516441 Share on other sites More sharing options...
Solution scootstah Posted July 15, 2015 Solution 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); 1 Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.