DrEdwiser Posted August 18, 2010 Share Posted August 18, 2010 I am using two diffrent databases in my php system, MySQL and MSSQL. my issue is i need a list of results from a MySQL query to be part of a Where clause in the MSSQL query. I cant put the the MSSQL query in the while section of the MySQL query as i need to sort by the results of the MSSQL query. if i do the MySQL query and then use the info from that in the MSSQL query I get only one result. so i decided to make it a function. how ever i need to know how to make the function into a variable so i can input it in the MSSQL query. Hope this all makes senes. heres what i have that is not working . function somefunction($vaiable) { $gers = mysql_query(sprintf("SELECT emp_id, lastname FROM info WHERE active='1' AND oid='$oid' AND pidnumber='4'")) or die(mysql_error()); while ($gerow = mysql_fetch_array($gers)) { echo "ci.attorney='$lastnamey' OR "; } } $attlist = getattorney($vaiable); echo $attlist; $rscw=odbc_exec($conn, sprintf("SELECT ci.attorney, SUM(ci.totalweight) AS 'citw' FROM info ci, clients cl WHERE ci.ID = cl.ID AND (cl.county = '$xca' OR cl.county ='$xcb' OR cl.county ='$xcc' OR cl.county ='$xcd') AND ($attlist ci.attorney='xyz') GROUP BY ci.attorney ORDER BY citw DESC")) or die (odbc_errormsg()); while (odbc_fetch_row($rscw)) { echo odbc_result($rscw,"attorney"); echo odbc_result($rscw,"citw"); } is there a way to make a function be defined as a variable? Any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/211065-function-as-a-variable/ Share on other sites More sharing options...
sasa Posted August 18, 2010 Share Posted August 18, 2010 change your function to function somefunction($vaiable) { $gers = mysql_query(sprintf("SELECT emp_id, lastname FROM info WHERE active='1' AND oid='$oid' AND pidnumber='4'")) or die(mysql_error()); $out =''; while ($gerow = mysql_fetch_array($gers)) { $out .= "ci.attorney='$lastnamey' OR "; } return $out; }[>/code] Quote Link to comment https://forums.phpfreaks.com/topic/211065-function-as-a-variable/#findComment-1100775 Share on other sites More sharing options...
DrEdwiser Posted August 18, 2010 Author Share Posted August 18, 2010 Fantastic! it worked like a champ, I certainly appreicate it! Quote Link to comment https://forums.phpfreaks.com/topic/211065-function-as-a-variable/#findComment-1100790 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.