Jump to content

Can I return values from a mysql query from inside a function?


poleposters

Recommended Posts

Hi,

 

I've just recently discovered how useful writing my own php functions are. I've been using them mostly to tidy up repetitive code.

 

However I want to know if this is possible. I have a mysql query which retrieves a customer's details from the database. I use it quite alot and want to place it inside a function. However I'm not sure how to return the values once the query is completed. I thought that the function might work similarly to an include, but this doesn't seem to be the case.

 

Is a function the right way to go about this?

 

 

$query="SELECT * FROM customers LEFT JOIN orders ON orders.customer_id=customers.customer_id LEFT JOIN contact ON contact.customer_id=customers.customer_id WHERE orders.order_id='$order_id'";
		$result=mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
		if(mysql_num_rows($result)>0)
		{
			while($select=mysql_fetch_array($result))
			{
			$first_names=$select['first_name'];
			$email=addslashes($select['email']);
			$invoice_location=$select['invoice_location'];
			}

		}	

 

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.