I have created a user defined function to return a string value
function getModel($part) {
$root = substr($part,0,4);
$query = "SELECT Root, Model FROM tbl_Root
WHERE Root = '$root'";
$result = mysql_query($query) or die ("Query Root failed: " . mysql_error());
while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) {
if (in_array($root, $rec)):
$Model = $rec['Model'];
else:
$Model = 'UNKNOWN';
endif;
}
return $Model;
}
When trying to find the attributes of several hundred part numbers, I pass them to a MySQL temp table that would then select the distinct part numbers and loop them through my functions.
$query = "SELECT DISTINCT A FROM TempAttributes";
$result = mysql_query($query) or die ("Query failed: " . mysql_error());
while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) {
$part = mysql_escape_string($rec['A']);
$Model = getModel($part);
$query = "REPLACE INTO tbl_Attributes
(Part, Model)
VALUES
('$part', '$Model')";
$endresult = mysql_query($query) or die ("Query Load failed: " . mysql_error());
}
The line of code that stops the execution of my loop is $Model = getModel($part); I executed the loop with this line of code in and it stops after the first part number. When I comment this line of code out, my loop processes all of my part numbers, but of course not with the return values I am looking for.
Why does my user defined function not process through the while loop to assign the $Model variable the return value of the getModel function?
Please help!