如何使用php、javascript排列表格

如何使用php、javascript排列表格,javascript,php,mysql,Javascript,Php,Mysql,这是一个php和javascript。我有一行代码,课程编号,课程描述,单位,时间,天数,房间。问题是我不能安排它。它显示courseDescription列中的所有数据。下面的图片是它现在的样子和我想要的样子 [ javascript $(document).ready(function() { $("#faq_search_input").watermark("Begin Typing to Search"); $("#faq_search_input").keyup(fun

这是一个php和javascript。我有一行代码,课程编号,课程描述,单位,时间,天数,房间。问题是我不能安排它。它显示courseDescription列中的所有数据。下面的图片是它现在的样子和我想要的样子

[ javascript

      $(document).ready(function() {

$("#faq_search_input").watermark("Begin Typing to Search");

$("#faq_search_input").keyup(function()
{
var faq_search_input = $(this).val();
var dataString = 'keyword='+ faq_search_input;
if(faq_search_input.length>3)

{
$.ajax({
type: "GET",
url: "search.php",
data: dataString,
beforeSend:  function() {

$('input#faq_search_input').addClass('loading');

},
success: function(server_response)
{

$('#searchresultdata').html(server_response).show();
$('span#faq_category_title').html(faq_search_input);

if ($('input#faq_search_input').hasClass("loading")) {
 $("input#faq_search_input").removeClass("loading");
        } 

}
});
}return false;
});
});
home.php

 <div id="SubjectOffering" class = "listTable" >
                 <p><h3> Subject Offering </h3> </p>
                 <p>
                     <div class = "searchBar">
                        <form id="searchbox" action="#" onsubmit="return false;">
                              <!-- The Searchbox Starts Here  -->
                <input  name="query" type="text" id="faq_search_input" />
                <!-- The Searchbox Ends  Here  -->




                        </form>

                    </div>
                </p>
                <p>
                <table>
                     <tr>
                        <td>Class Code</td>
                        <td>Course Number</td>      
                        <td>Course Description</td>

                        <td>Time</td>
                        <td>Days</td>
                        <td>Room</td>
                      </tr>

                     <tr>
                        <td></div></td>
                        <td></td>       
                        <td><div id="searchresultdata" class="faq-articles"> </td>
                        <td> </td>
                        <td> </td>      
                        <td></td>
                        <td> </td>
                      </tr>
                      </table>

主题发行

类别代码 课程号 课程描述 时间 天 房间
search.php

 <?php
 include_once ('connections.php');

 if(isset($_GET['keyword'])){
  $keyword =    trim($_GET['keyword']) ;
  $keyword = mysqli_real_escape_string($dbc, $keyword);

     $query = "select courseCode,classcode,courseDescription,time,day,room      from class where classcode like '%$keyword%' or courseDescription like '%$keyword%' or courseCode like '%$keyword%' or time like '%$keyword%'
  or day like '%$keyword%' or room like '%$keyword%'";

 //echo $query;
 $result = mysqli_query($dbc,$query);
 if($result){
 if(mysqli_affected_rows($dbc)!=0){
      while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){

 echo '<p> <b>'.$row['classcode'].'</b> '.$row['courseCode']. '</b>'.$row['courseDescription'].'</b> '.$row['time'].'</b> '.$row['day'].'</b> '.$row['room'].'</p>';
     }
    }else {
    echo 'No Results for :"'.$_GET['keyword'].'"';
   }

 }
 }else {
echo 'Parameter Missing';
 }

 ?>

您的代码中几乎没有html标记错误,例如未使用的标记。我刚刚修改了您的代码。请验证是否发现任何错误,然后告诉我

您的JAVASCRIPT/JQUERY代码应如下所示:

/**
 * @description: Update result when user searches.
 * @author Vivek Keviv
 * @params none
 * @return none
 */
$ (document).ready(function() {
    $("#faq_search_input").watermark("Begin Typing to Search");
    $("#faq_search_input").keyup(function() {
        var faq_search_input = $(this).val();
        var dataString = 'keyword='+ faq_search_input;
        if (faq_search_input.length>3) {
            $.ajax({
                type: "GET",
                url: "search.php",
                data: dataString,
                beforeSend: function() {
                    $('input#faq_search_input').addClass('loading');
                },
                success: function(server_response) {
                    $('#searchresultdata').html(server_response).show();
                    $('span#faq_category_title').html(faq_search_input);
                    if ($('input#faq_search_input').hasClass("loading")) {
                        $("input#faq_search_input").removeClass("loading");
                    } 
                }
            });
        }
        return false;
    });
});
<div id="SubjectOffering" class="listTable">
    <p>
        <h3>Subject Offering</h3>
    </p>
    <div class="searchBar">
        <form id="searchbox" action="#" onsubmit="return false;">
            <!-- The Searchbox Starts Here  -->
            <input  name="query" type="text" id="faq_search_input" />
            <!-- The Searchbox Ends  Here  -->
        </form>
    </div>
    <div id="searchresultdata" class="faq-articles">
        <table>
            <tr>
                <th>Class Code</th>
                <th>Course Number</th>      
                <th>Course Description</th>
                <th>Time</th>
                <th>Days</th>
                <th>Room</th>
            </tr>
            <tr>
                <td></td>
                <td></td>       
                <td></td>
                <td></td>
                <td></td>      
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
</div>
<?php
include_once ('connections.php');
if (isset($_GET['keyword'])) {
    $keyword =    trim($_GET['keyword']) ;
    $keyword = mysqli_real_escape_string($dbc, $keyword);

    $query = "select courseCode,classcode,courseDescription,time,day,room      from class where classcode like '%$keyword%' or courseDescription like '%$keyword%' or courseCode like '%$keyword%' or time like '%$keyword%'
    or day like '%$keyword%' or room like '%$keyword%'";

    //echo $query;
    $result = mysqli_query($dbc,$query);
    if ($result) {
        if (mysqli_affected_rows($dbc)!=0) { ?>
            <table>
                <tr>
                    <th>Class Code</th>
                    <th>Course Number</th>      
                    <th>Course Description</th>
                    <th>Time</th>
                    <th>Days</th>
                    <th>Room</th>
                </tr>            
                <?php while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { ?>
                        <tr>
                            <td><?php echo $row['classcode']; ?></td>
                            <td><?php echo $row['courseCode']; ?></td>       
                            <td><?php echo $row['courseDescription']; ?></td>
                            <td><?php echo $row['time']; ?></td>
                            <td><?php echo $row['day']; ?></td>
                            <td><?php echo $row['room']; ?></td>
                        </tr>
                <?php } ?>
            </table>
        <?php } else {
            echo 'No Results for :"'.$_GET['keyword'].'"';
        }
    }
} else {
    echo 'Parameter Missing';
}
?>
您的HTML代码应如下所示:

/**
 * @description: Update result when user searches.
 * @author Vivek Keviv
 * @params none
 * @return none
 */
$ (document).ready(function() {
    $("#faq_search_input").watermark("Begin Typing to Search");
    $("#faq_search_input").keyup(function() {
        var faq_search_input = $(this).val();
        var dataString = 'keyword='+ faq_search_input;
        if (faq_search_input.length>3) {
            $.ajax({
                type: "GET",
                url: "search.php",
                data: dataString,
                beforeSend: function() {
                    $('input#faq_search_input').addClass('loading');
                },
                success: function(server_response) {
                    $('#searchresultdata').html(server_response).show();
                    $('span#faq_category_title').html(faq_search_input);
                    if ($('input#faq_search_input').hasClass("loading")) {
                        $("input#faq_search_input").removeClass("loading");
                    } 
                }
            });
        }
        return false;
    });
});
<div id="SubjectOffering" class="listTable">
    <p>
        <h3>Subject Offering</h3>
    </p>
    <div class="searchBar">
        <form id="searchbox" action="#" onsubmit="return false;">
            <!-- The Searchbox Starts Here  -->
            <input  name="query" type="text" id="faq_search_input" />
            <!-- The Searchbox Ends  Here  -->
        </form>
    </div>
    <div id="searchresultdata" class="faq-articles">
        <table>
            <tr>
                <th>Class Code</th>
                <th>Course Number</th>      
                <th>Course Description</th>
                <th>Time</th>
                <th>Days</th>
                <th>Room</th>
            </tr>
            <tr>
                <td></td>
                <td></td>       
                <td></td>
                <td></td>
                <td></td>      
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
</div>
<?php
include_once ('connections.php');
if (isset($_GET['keyword'])) {
    $keyword =    trim($_GET['keyword']) ;
    $keyword = mysqli_real_escape_string($dbc, $keyword);

    $query = "select courseCode,classcode,courseDescription,time,day,room      from class where classcode like '%$keyword%' or courseDescription like '%$keyword%' or courseCode like '%$keyword%' or time like '%$keyword%'
    or day like '%$keyword%' or room like '%$keyword%'";

    //echo $query;
    $result = mysqli_query($dbc,$query);
    if ($result) {
        if (mysqli_affected_rows($dbc)!=0) { ?>
            <table>
                <tr>
                    <th>Class Code</th>
                    <th>Course Number</th>      
                    <th>Course Description</th>
                    <th>Time</th>
                    <th>Days</th>
                    <th>Room</th>
                </tr>            
                <?php while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { ?>
                        <tr>
                            <td><?php echo $row['classcode']; ?></td>
                            <td><?php echo $row['courseCode']; ?></td>       
                            <td><?php echo $row['courseDescription']; ?></td>
                            <td><?php echo $row['time']; ?></td>
                            <td><?php echo $row['day']; ?></td>
                            <td><?php echo $row['room']; ?></td>
                        </tr>
                <?php } ?>
            </table>
        <?php } else {
            echo 'No Results for :"'.$_GET['keyword'].'"';
        }
    }
} else {
    echo 'Parameter Missing';
}
?>


主题发行

类别代码 课程号 课程描述 时间 天 房间
您的PHP代码应如下所示:

/**
 * @description: Update result when user searches.
 * @author Vivek Keviv
 * @params none
 * @return none
 */
$ (document).ready(function() {
    $("#faq_search_input").watermark("Begin Typing to Search");
    $("#faq_search_input").keyup(function() {
        var faq_search_input = $(this).val();
        var dataString = 'keyword='+ faq_search_input;
        if (faq_search_input.length>3) {
            $.ajax({
                type: "GET",
                url: "search.php",
                data: dataString,
                beforeSend: function() {
                    $('input#faq_search_input').addClass('loading');
                },
                success: function(server_response) {
                    $('#searchresultdata').html(server_response).show();
                    $('span#faq_category_title').html(faq_search_input);
                    if ($('input#faq_search_input').hasClass("loading")) {
                        $("input#faq_search_input").removeClass("loading");
                    } 
                }
            });
        }
        return false;
    });
});
<div id="SubjectOffering" class="listTable">
    <p>
        <h3>Subject Offering</h3>
    </p>
    <div class="searchBar">
        <form id="searchbox" action="#" onsubmit="return false;">
            <!-- The Searchbox Starts Here  -->
            <input  name="query" type="text" id="faq_search_input" />
            <!-- The Searchbox Ends  Here  -->
        </form>
    </div>
    <div id="searchresultdata" class="faq-articles">
        <table>
            <tr>
                <th>Class Code</th>
                <th>Course Number</th>      
                <th>Course Description</th>
                <th>Time</th>
                <th>Days</th>
                <th>Room</th>
            </tr>
            <tr>
                <td></td>
                <td></td>       
                <td></td>
                <td></td>
                <td></td>      
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
</div>
<?php
include_once ('connections.php');
if (isset($_GET['keyword'])) {
    $keyword =    trim($_GET['keyword']) ;
    $keyword = mysqli_real_escape_string($dbc, $keyword);

    $query = "select courseCode,classcode,courseDescription,time,day,room      from class where classcode like '%$keyword%' or courseDescription like '%$keyword%' or courseCode like '%$keyword%' or time like '%$keyword%'
    or day like '%$keyword%' or room like '%$keyword%'";

    //echo $query;
    $result = mysqli_query($dbc,$query);
    if ($result) {
        if (mysqli_affected_rows($dbc)!=0) { ?>
            <table>
                <tr>
                    <th>Class Code</th>
                    <th>Course Number</th>      
                    <th>Course Description</th>
                    <th>Time</th>
                    <th>Days</th>
                    <th>Room</th>
                </tr>            
                <?php while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { ?>
                        <tr>
                            <td><?php echo $row['classcode']; ?></td>
                            <td><?php echo $row['courseCode']; ?></td>       
                            <td><?php echo $row['courseDescription']; ?></td>
                            <td><?php echo $row['time']; ?></td>
                            <td><?php echo $row['day']; ?></td>
                            <td><?php echo $row['room']; ?></td>
                        </tr>
                <?php } ?>
            </table>
        <?php } else {
            echo 'No Results for :"'.$_GET['keyword'].'"';
        }
    }
} else {
    echo 'Parameter Missing';
}
?>

谢谢和问候


Vivek

@Maecece Liz始终尝试在代码中使用缩进,以便您能够轻松理解代码,并能够调试和识别代码块,否则您肯定会感到困惑。注意:不要在class属性及其值之间留空格,如下所示:
class=“searchBar”
使用like
class=“searchBar”
我更改了代码,请检查。很抱歉,我没有运行代码并将其提供给您。我只是用肉眼检查并进行了更正,然后给出了答案。