从基于HTML表单的MySQL中选择

时间:2016-01-27 12:42:24

标签: php html mysql

HTML表单包含4个字段(名字,姓氏,移动和出席)。这是一个搜索表单,用于在参与mysql表中查找记录。所有这些字段都是可选的,意图是您在表单中输入的字段越多,您缩小搜索范围。我知道问题在于第一个SQL,因为它没有考虑所有变量。

将第二位混淆在更多...在表中回显结果的情况下,回显表的最后一个字段应包含从第二个SQL语句中选择的数据,但此数据在另一个表中。

对不起,如果有什么内容含糊不清,但我不知道如何处理这个问题,看了太长时间了!

非常感谢你的帮助!

<html>
<body>
<table>
<table border="1">
<tr><th>AttendeeID</th><th>Wristband</th><th>Firstname</th><th>Lastname</th><th>Telephone
</th><th>Mobile</th><th>Address 1</th><th>Address 2</th><th>Town</th><th>Postcode</th><th>
E-Mail</th><th>Medical Notes</th><th>Last Reader Tap</th></tr>

<?php

include "checkmysqlconnect.php";

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$mobile = $_POST['mobile'];
$attendid = $_POST['attendid'];
$search = $_POST['search'];

if ($search == "Search") {
    if ($firstname == '' AND $lastname == '' AND $attendid == '' AND $mobile == '') {
        header("Location: searchattendform.php?result=1");
        $error = true;
    }

    if ($error != true) {

$sql = "SELECT * FROM `attend` WHERE `firstname` = '".$firstname."' OR `lastname` = '".$lastname."' OR `attendid` = '".$attendid."' OR `mobile` = '".$mobile."'";
$query = mysql_query($sql);
$count = mysql_num_rows($query);

$sql1 = "SELECT `readerid` FROM `taps` WHERE `attendid` = '".$attendid."' ORDER BY `time` DESC LIMIT 1";
$query1 = mysql_query($sql1);

if ($count > 1) {
    echo "More than one matching attendee. Entering more details will help narrow down results.";
while($value = mysql_fetch_assoc($query));
while($value1 = mysql_fetch_assoc($query1)) {   
    echo "<tr><td>".$value['attendid']."</td><td>".$value['wristband']."</td><td>".$value['firstname'].
    "</td><td>".$value['lastname']."</td><td>".$value['telephone']."</td><td>".$value['mobile']."</td><td>".$value['address1'].
    "</td><td>".$value['address2']."</td><td>".$value['town']."</td><td>".$value['postcode']."</td><td>".$value['email'].
    "</td><td>".$value['medical']."</td><td>".$value1['readerid']."</td></tr>";
} } else {
    if ($count == 0) {
        header("Location: searchattendform.php?result=2");
} else {
    if ($count == 1) {
        ($value = mysql_fetch_assoc($query));
            echo "<tr><td>".$value['attendid']."</td><td>".$value['wristband']."</td><td>".$value['firstname'].
        "</td><td>".$value['lastname']."</td><td>".$value['telephone']."</td><td>".$value['mobile']."</td><td>".$value['address1'].
        "</td><td>".$value['address2']."</td><td>".$value['town']."</td><td>".$value['postcode']."</td><td>".$value['email'].
        "</td><td>".$value['medical']."</td><td>".$value1['readerid']."</td></tr>";
    } else {
        echo "There was an issue searching attendees. Please contact SOFia Admin.";
    } }
}
}
}

?>

</table>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

看一下外循环while($value = mysql_fetch_assoc($query));

这不应该是while($value = mysql_fetch_assoc($query)){吗?