我写了一个查询来从我的数据库中获取客户信息,但说我想在另一个页面上使用它。我不想复制并粘贴到其他页面来使用它。
我看过一个函数,但我不知道如何从函数中取出变量。
这是我目前的功能:
function getCustomer($customerid) {
$getcustomer = mysql_query("SELECT * FROM hire_customers WHERE 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'];
}
这是我的客户页面
getCustomer($customerid);
echo $cust_firstname;
但没有任何回应。
我需要查看一个类或对象来执行此操作吗?我的功能有问题吗?
我想做的是在一个地方拥有一个包含我所有客户功能(更新、选择等)的 PHP 文件。