无法使用php从数据库打印数据

时间:2014-04-04 15:19:24

标签: php mysql

我正在开发这个应用程序,它应该显示具有特殊技能的学生。我正在测试我的应用程序,我发现它不打印任何东西。几乎花了一个小时,并且无法弄清楚问题是什么。

    <html>
   <head>
        <title>PHP Filter</title>
        <script type="text/javascript">
        function change_input() {
            var Select;
            var Input;

            Select = document.getElementById('criteria_no');
            Input = document.getElementById('input');

            if (Select.value == '1') {
                Input.innerHTML = 'Criteria 1:<input type="text" name="criteria1" value=""><br><input type="submit">';
            } else if (Select.value == '2') {
                Input.innerHTML = 'Criteria 1:<input type="text" name="criteria1" value=""><br>Criteria 2:<input type="text" name="criteria2" value=""><br><input type="submit">';
            } else if (Select.value == '3') {
                Input.innerHTML = 'Criteria 1:<input type="text" name="criteria1" value=""><br>Criteria 2:<input type="text" name="criteria2" value=""><br>Criteria 3:<input type="text" name="criteria3" value=""><br><input type="submit">';

            } else {
                Input.innerHTML = '';
            }
        }

    </script>
</head>
<body>
    <form method="post" action="filter.php">
        Please choose the number of fields
        <select name="criteria_no" id="criteria_no" onchange="change_input();">
            <option value="0">Select</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <br>

        <span id="input"></span>
    </form>
</body>
</html>

<?php
require ("config.inc.php");
if (!empty($_POST)) {
    $criteria_no = $_POST['criteria_no'];
   if ($criteria_no == '1') {
    $criteria1 = '%' . $_POST['criteria1'] . '%';
    $search = "SELECT `username` ,`email_id`, `avg` , `skills` FROM `academic` WHERE `skills` LIKE '.$criteria1.' ORDER BY `avg` ASC ";
    echo '<table><tr><th>Username</th><th>Email Id</th><th>Avg</th><th>Skills</th></tr>';
    $result = mysql_query($search) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        echo '<tr>';
        echo '<td>' . $row['username'] . '</td>';
        echo '<td>' . $row['email_id'] . '</td>';
        echo '<td>' . $row['avg'] . '</td>';
        echo '<td>' . $row['skills'] . '</td>';
        echo '</tr>';
    }
    echo '</table>';
} else if ($criteria_no == '2') {
    echo "2";
} else if ($criteria_no == '3') {
    echo "3";
}
}
?>

1 个答案:

答案 0 :(得分:0)

$search = "SELECT `username` ,`email_id`, `avg` , `skills` FROM `academic` WHERE `skills` LIKE '".$criteria_1."' ORDER BY `avg` ASC ";