根据id表将单个数组结果发送到打印机
Send individual array results to printer based on id table
我正在编写一个简单的PHP脚本,该脚本将用户详细信息存储在MySQL数据库中。我可以运行一个查询,并让它返回单个记录,只要查询与姓氏匹配(预定义)。一旦我有了记录,我希望能够在每个记录旁边回显一个打印按钮,这样用户就可以单独打印每个记录。
该代码是几个代码片段的混搭,除了"打印用户数据"部分外,其他部分都运行良好。我不是PHP的新手,但我也有足够的知识来浏览脚本。以下是我迄今为止的收获。
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['keyname']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
//database connection info
$host = "localhost"; //server
$db = "users"; //database name
$user = "root"; //dabases user name
$pwd = "password1"; //password
//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);
//MYSQL search statement
$query = "SELECT * FROM details WHERE lastname LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
/* check whether there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
echo "<tr valign=bottom>";
echo "<td bgcolor=#ffffff background='img/dots.gif' colspan=6><img src=img/blank.gif width=1 height=1></td>";
echo "</tr>";
echo "<tr valign=center>";
echo "<td class=tabval><img src=img/blank.gif width=10 height=20></td>";
echo "<td class=tabval><b>".htmlspecialchars($row['firstname'])."</b> </td>";
echo "<td class=tabval>".htmlspecialchars($row['lastname'])." </td>";
echo "<td class=tabval>".htmlspecialchars($row['address'])."</td> ";
echo "<td class=tabval>".htmlspecialchars($row['phone'])." </td>";
echo "<button type='"button'" class='"formbutton'" onclick='"printpage('" . $lastname . "'); '">Print User Data</button>";
echo "<td class=tabval></td>";
echo "</tr>";
$i++;
}
echo "<tr valign=bottom>";
echo "<td bgcolor=#fb7922 colspan=6><img src=img/blank.gif width=1 height=8></td>";
echo "</tr>";
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?>
<br />
<a href="javascript:history.go(-1)">Done</a>
echo "<button type='"button'" class='"formbutton'" onclick='"printpage('" . $lastname . "'); '">Print User Data</button>";
此行调用一个名为"printpage"的javascript函数。一旦你在页面上有了javascript函数,你就会更接近你的预期结果。
相关文章:
- 奇怪的Javascript结果
- Javascript(jQuery)给了我奇怪的结果
- JSONP请求返回结果,但也触发error_callback
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Javascript,输出结果后页面不断刷新
- 这是使用html快照和谷歌获取的预期结果吗?SEO/SPA
- 将地理编码结果转换为php变量以发布到mysql数据库
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- JQuery:向多个匹配结果添加换行符的最简单方法
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- webpack代码拆分了handlerbs文件——结果是文件很大
- JavaScript循环无法正确计算/显示结果
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- Node.js使用Series函数(模式?)实现流控制时出现意外结果
- 试图将onChange函数作为道具传递给GrandChlidren,结果是TypeError:这是未定义的
- jQuery使用api获取typeform结果
- 根据条件检查数据库结果
- 什么'这是从第三个函数上的async 1st函数获得结果的更好方法
- Angular,表达式{{}}的结果没有插入到ng-click中
- 根据id表将单个数组结果发送到打印机