0

Hi,
I use a query which is identical throughtout my application, only thing that differs is the select part of the query,

so for example:

 mysql_select_db("mydatabase", $con);
 $result4 = mysql_query("SELECT * FROM nap where Exchange  LIKE '$majorvalue%'");
 while($row = mysql_fetch_array($result4))
 {
$psba = $row['Site'];
$status = $row['Status'];
$spectrum = $row['InSpectrum']; 
$exchange = $row['Exchange'];
$exchange = str_replace("_"," ",$exchange);
$street = $row['Street'];
$city = $row['City'];
$county = $row['County'];
$zip = $row['Zip_Postal_Code'];
$circuit = $row['Circuit Details'];
$groupname = $row['Site_Group'];
// LETS GET RID OF UNDERSCORES AND SPACES ETC..
$expr = '/(?<=\s|^)[a-z]/i';
preg_match_all($expr, $groupname, $matches);
$newresult = implode('', $matches[0]);
$newresult = strtoupper($newresult);
/* echo statements here*/
}

The only bit that ever will change is the select statements, so I wanted to put the repeat code as a function and call it after the select statement so it would read:

    mysql_select_db("mydatabase", $con);
    $result4 = mysql_query("SELECT * FROM nap where Exchange LIKE '$majorvalue%'");
    while($row = mysql_fetch_array($result4))
    {
    myfunction();
    }

I just cant seem to get it too work?

2
Contributors
4
Replies
13
Views
3 Years
Discussion Span
Last Post by Atli
0

How does your myfunction() code look like?

If it's just about getting the $row variable into the function, so it can be deal with in there, pass it in there as a function parameter.

// Function definition
function myFunction($row) {
    // Use $row here...
}

// Calling code
while ($row = ...) {
    myFucntion($row);
}
0

my function code is just the extracted variables like this:

function mycode(){
$psba = $row['Site'];
$status = $row['Status'];
$spectrum = $row['InSpectrum'];
$exchange = $row['Exchange'];
$exchange = str_replace("_"," ",$exchange);
$street = $row['Street'];
$city = $row['City'];
$county = $row['County'];
$zip = $row['Zip_Postal_Code'];
$circuit = $row['Circuit Details'];
$groupname = $row['Site_Group'];
// LETS GET RID OF UNDERSCORES AND SPACES ETC..
$expr = '/(?<=\s|^)[a-z]/i';
preg_match_all($expr, $groupname, $matches);
$newresult = implode('', $matches[0]);
$newresult = strtoupper($newresult);
/* echo statements here*/
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.