Jump to content

Function as a variable


DrEdwiser

Recommended Posts

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

Link to comment
Share on other sites

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]

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.