Jump to content

[SOLVED] using result from array in subsequent query


Walker33

Recommended Posts

I'm getting an array, and I want to use use each result in a subsequent query, but I'm not sure how to name the returned array to place it in the second query.  So I'm trying to get license to equal all the results echoed in $row5['License_Num'] and echo whatever the second query returns.  Stumped.

 

<?php
<?		if ($result["r_approved"] == "APPROVED")    // transaction processed successfully
	// check demo table if Initiator is reporter to see if they have a demo license:
{
$query5 = ("SELECT License_Num FROM demo_details WHERE ((RFirstName like '%$FName1%' AND RLastName like '%$LName1%') OR (REmail = '$billing_email') OR (SFirstName like '%$FName1%' AND SLastName like '%$LName1%') OR (SEmail = '$billing_email'))");
$result5 = mysql_query($query5) or die(mysql_error());
while($row5 = mysql_fetch_array($result5)){
echo $row5['License_Num'];
echo "<br />";

//check trial license table to see if any results from 1st query exist 
$query6 = ("SELECT license FROM triallics WHERE license = '???'");
$result6 = pg_query ($query6);
$row6 = pg_fetch_array ($result6);
echo $row6['license'];

}

echo "you have some rows";

}

?>

 

As always, any help is GREATLY appreciated!

Create a comma delimited string  like this:

<?php
$myString="";
while($row5 = mysql_fetch_array($result5)){
    $myString.="'".$row5['license_Num']."',";
}
?>

 

which will create a String like this: 'string1','string2',etc...

 

then in your SQL use the 'IN' command like so:

<?php
$query6 = ("SELECT license FROM triallics WHERE license IN (".$myString."));
?>

 

or, to get a single license, do the same this but as so:

<?php
$myString="";
while($row5 = mysql_fetch_array($result5)){
    $myString =$row5['license_Num'];
    $query6 = ("SELECT license FROM triallics WHERE license = $myString");
// echo as needed
}
?>

Still not getting any output for $license6 .  Wasn't sure how to use Ken's substring.  I know there's at least one value, because when I make license = 'value' , it spits it out.

 

<?php
$query5 = ("SELECT License_Num FROM demo_details WHERE ((RFirstName like '%$FName1%' AND RLastName like '%$LName1%') OR (REmail = '$billing_email') OR (SFirstName like '%$FName1%' AND SLastName like '%$LName1%') OR (SEmail = '$billing_email'))");
$result5 = mysql_query($query5) or die(mysql_error());
$myString="";
while($row5 = mysql_fetch_array($result5)){
    $myString.="'".$row5['License_Num']."',";
echo $row5['License_Num'];
echo "<br />";

//check trial license table to see that they're still in there
$query6 = pg_query("SELECT license FROM triallics WHERE license IN (".$myString.")");
$getarray = pg_fetch_assoc($query6);
$license6 = $getarray['license'];
echo $license6 ;
}
?>

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.