【发布时间】:2016-03-01 08:00:40
【问题描述】:
我需要一种方法让用户将数据粘贴到表单中的文本区域中
并单独查询每一行。
例如 - 假设用户需要获取每个人的年龄
从分贝。而不是一次做一个名字 - 用户粘贴
10 个名字。
名称1
名称2
name3 等
然后用户提交表单,php输出为:
名称1 | 43
名称2 | 21
名称3 | 17 等
有什么建议吗?
谢谢
<?php
//dbstuff:
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$list = explode("\r\n", htmlentities($_POST['name'])); // 'names' is the name of your textarea; I use htmlentities to help sanitize the data; $list is now an array of the entries split by a new line character
foreach($list as $l){
$name = $l;
//query the DB
$query= "select peg_site_id, fa_code from cpm where peg_site_id='". $name."'";
}
//DEBUG
$debug = 1; //Select 1 for ON, or 2 for OFF
if ($debug == 1){
echo "<br /><br />START DEBUG<br />" . "*********************************<br />" . $query. "<br /><br />" . $count_query. "<br /><br />" . "*********************************<br />" . "END DEBUG<br />";
}
else {
echo "";
}
?>
<html>
<head>
<style type="text/css">
h4 {font-family: sans-serif}
p {font-family: courier}
p.sansserif {font-family: sans-serif}
</style>
</head>
<body>
<?php
// Print out result
$result= mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<b>Customer Site ID:</b> ".$row['fa_code'] . " <b>Site ID:</b> ".$row['peg_site_id'] . "</br>";
//echo "--------------------------------------------------------";
//echo "</br></br>";
}
?>
</font>
【问题讨论】: