Jump to content

[SOLVED] An easier method


IronWarrior

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/122268-solved-an-easier-method/
Share on other sites

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.