2011-03-16 95 views
-1

我在一個HTML頁面中有一個組合框另一個頁面我想調用數據庫中的數據庫選擇客戶名稱這些名稱分別在組合框中顯示。請爲我代碼。通過我的sql下拉列表

+4

我們不會爲你做,告訴我們到目前爲止你所擁有的,別人也許能幫助你。 – mdm 2011-03-16 08:19:21

回答

1

首先,Don't use mysql_* functions in new code。他們不再維護and are officially deprecated。請參閱red box?請改爲了解prepared statements,並使用PDOMySQLi - this article將幫助您決定哪個。如果您選擇PDO,here is a good tutorial


<?php 
$db_name = "db"; 
$connection = mysql_connect('localhost','root','') or die(mysql_error()); 
$db = mysql_select_db($db_name,$connection) or die(mysql_error()); 
$sql = "SELECT customer_name,id from customers ORDER BY customer_name desc"; 
$result = mysql_query($sql,$db) or die(mysql_error()); 
if(mysql_num_rows($result)>=1){ 
    $form = '<form method="POST" action=""> 
    <p>Customer name:<select size="1" name="customer">'; 
    while ($row = mysql_fetch_array($result)) { 
     $form .='<option value="'.$row['id'].'">'.ucwords($row['customer_name']).'</option>'; 
    } 
    $form .=' </select></p><p><input type="submit" value="Submit"></p></form>'; 
} 
echo $form; 
?> 
相關問題