Jump to content

Use data from previous query


rvdveen27

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.