我有一个名为clients的sql表,其中每个客户端都存储在一行中,具有唯一(自动增量)id,列名称为:clientname,clientlastname,clientmobile等。
我想创建一个数组来检索特定客户端(行)的内容,并且类似于:clientname => lalala, clientlasthname=>lalalala...
等等。
然后我想以html格式显示结果(不可提交,只显示) 表单中的每个单元格都有一个唯一的id和名称,与sql db的列名相同。
我刚接触它并且似乎无法得到它。 这是我到目前为止所做的:
<?php
header("Content-Type:text/html; charset=utf-8");
if ($_POST) {
$link = mysql_connect("localhost","userid","pw");
if (!$link) { die("Database Connection Failed". mysql_error()); }
mysql_set_charset('utf8',$link);
$db_select = mysql_select_db("form2",$link);
if(!$db_select){ die("Database Selection Failed " . mysql_error()); }
} else { echo "Search:"; }
?>
<html>
<head> </head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="css/dsearch.css" />
<link rel="stylesheet" href="css/base.css" />
<link type="text/css" href="css/selected/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="js/dropdowndata.sql/dropdowndata.clients.js"></script>
<script language="javascript" type="text/javascript" src="js/buttons.js"></script>
<body>
<form class="form" id="dsearch" name="dsearch" action="dsearch.php" method="POST" enctype="application/x-www-form-urlencoded">
<div class="dsearch">
<li class="ui-widget"><label for="clients">client id: </label><input class="client" name="searchcid" style="width:100px" /></li>
<li class="cell3"><input type="submit" value="Αναζήτηση" style="color:green; width:210px; " /></li>
</div>
</form>
<div class="results">
<?php
$result1 = mysql_query("SELECT * FROM clients WHERE id='$_POST[searchcid]'", $link);
if(!$db_select) { die("No Data found in db " . mysql_error()); };
$items=array();
while($row = mysql_fetch_array($result1)){
$items[$row['id']] = $row['dlastname'];
/* here is where I need the help I guess,
I need to fill the $items array with the data formatted as mentioned above.
And after that I want to populate a form that I haven't already written with the
values ,any help or maybe any suggestions on some tutorials I could go study
would be appreciated.
It goes on like this: */
}
print_r ($items);
?>
</div>
</body>
</html>
<?php
if ($_POST) {
mysql_close($link);
}
?>
编辑:想出如何获取数组
$clinfo=array();
$clinfo=mysql_fetch_assoc($result1);
print_r ($clinfo);
现在我需要一种方法来将数据放在字段id等于docinfo数组的id
答案 0 :(得分:0)
想出如何用一点点php和jquery来做, 这是:
$(document).ready(function(){
<?php
if($_GET){
foreach($docinfo as $key=>$val) {
echo "$('#" . $key . "').val('" . htmlspecialchars($val) ."');";
}
}
?>
});
这会为每个单元格id创建一个jquery行,并使用适当的值
填充它非常感谢任何评论或改进