Walker33 Posted May 13, 2009 Share Posted May 13, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/157992-solved-using-result-from-array-in-subsequent-query/ Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157992-solved-using-result-from-array-in-subsequent-query/#findComment-833370 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 radi8, $myString will have an extra comma at the end. You would want to use substr($myString, 0, -1) on it. Edit - forgot to close your quotes in your second block of code. Quote Link to comment https://forums.phpfreaks.com/topic/157992-solved-using-result-from-array-in-subsequent-query/#findComment-833371 Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 nice catch, thanks Ken2K7. Quote Link to comment https://forums.phpfreaks.com/topic/157992-solved-using-result-from-array-in-subsequent-query/#findComment-833372 Share on other sites More sharing options...
Walker33 Posted May 13, 2009 Author Share Posted May 13, 2009 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 ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157992-solved-using-result-from-array-in-subsequent-query/#findComment-833524 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.