Jump to content

Use data from previous query


rvdveen27
Go to solution Solved by scootstah,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.