php - Variable invisible outside a function -
i have written query customer information database want use on page. don't want have copy , paste other page use it.
i have looked @ function don't know how variables out of function.
this current function:
function getcustomer($customerid) { $getcustomer = mysql_query("select * hire_customers id='".$customerid."'"); $fetch = mysql_fetch_assoc($getcustomer); $cust_firstname = $fetch['firstname']; $cust_lastname = $fetch['lastname']; $cust_address = $fetch['address']; $cust_town = $fetch['town']; $cust_postcode = $fetch['postcode']; $cust_cont1 = $fetch['contact1']; $cust_number1 = $fetch['contactnumber1']; $cust_cont2 = $fetch['contact2']; $cust_number = $fetch['contactnumber2']; $cust_email = $fetch['email']; $cust_idform1 = $fetch['idform1']; $cust_idnfo1 = $fetch['idinfo1']; $cust_idform2 = $fetch['idform2']; $cust_idinfo2 = $fetch['idinfo2']; $cust_enterdby = $fetch['enteredby']; } this customer page
getcustomer($customerid); echo $cust_firstname; but nothing echoed out.
do need looking @ class or object this? have gone wrong function.
what have php file customer functions (update, select, etc) in 1 place.
i think should return $fetch , access variable outside of function.
function getcustomer($customerid) { $customerid = mysql_real_escape_string($customerid); $getcustomer = mysql_query("select * hire_customers id='".$customerid."'"); $fetch = mysql_fetch_assoc($getcustomer); return $fetch; } $data=getcustomer($customerid); echo data['firstname'];
Comments
Post a Comment