This is php code, so this is definitely the wrong forum.
First, I wouldn't do this:
Code:
if ($nu = "New") {
$nu = "1";
}
else
{
if ($nu = "Used") {
$nu = "0";
}
It is bizarre to leave that burden on a function directly unless that's its actual job. Let it have $nu equating to only true and false. Let the caller decide what it considers true and false.
Next, don't do this:
Globalization is a debugging nightmare. Since they are global they are references, and will autodeclare if they do not exist. Changes out of scope are reflected in every scope, so this makes debugging exceedingly difficult. Unless there is a reason for it such as a locked function signature (used by callbacks in php such as usort, set_error_handler, etc), then always write to pass in a variable instead of globalizing it.
So effectively, we're now down to this:
PHP Code:
function coach_meta2($dbh, $nu = false)
{
$output = '';
$coach_meta = coach_meta($data['ID']);
// no, call this something different: $nu = ($coach_meta['ecpt_newused']);
$cm = $coach_meta['ecpt_newused'];
$qry = mysql_query($query); // again, something different
while($data2 = mysql_fetch_assoc($qry))
{
$output = $data2; // this will overwrite $output. If you want to append, use .= instead. If you do not want to append, use a LIMIT on the query and order in reverse. Then pull just the first record
}
return $output;
}
So, we now have a few problems.
- What is $data?
- What is $query?
- What is the purpose of both $nu and $dbh?
- What is the purpose of pulling $coach_meta, and ultimately the $cm I created from it?