IronWarrior Posted September 1, 2008 Share Posted September 1, 2008 I currently have a function as follows: function hasRelatedItems($vehicleType,$vehicleID) { $query = "SELECT vehicleID,vehicleName,vehicleType FROM vehiclesForSale WHERE vehicleType = '$vehicleType' AND vehicleID != '$vehicleID' AND isActive = '1'"; $result = mysql_query($query); $resultRow = mysql_fetch_array($result); $GLOBALS["hasRelatedItems"] = mysql_num_rows($result); $GLOBALS["hasRelatedVehicleID"] = $resultRow['vehicleID']; $GLOBALS["hasRelatedVehicleName"] = $resultRow['vehicleName']; $GLOBALS["hasRelatedVehicleType"] = $resultRow['vehicleType']; } It works well, but using Global s isn't a great practise, any advice on how to get around this. IronWarrior Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 1, 2008 Share Posted September 1, 2008 Try this: function hasRelatedItems($vehicleType,$vehicleID) { $query = "SELECT vehicleID,vehicleName,vehicleType FROM vehiclesForSale WHERE vehicleType = '$vehicleType' AND vehicleID != '$vehicleID' AND isActive = '1'"; $result = mysql_query($query); $resultRow = mysql_fetch_array($result); return array(mysql_num_rows($result),$resultRow['vehicleID'],$resultRow['vehicleName'],$resultRow['vehicleType']); } $items = hasRelatedItems('car',23); print_r($items); Quote Link to comment 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.