无法使此代码正常工作! [英] Cannot get this code working!

查看:103
本文介绍了无法使此代码正常工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我试图通过升序和降序选项在两列(名称和价格)中对搜索结果进行排序。我使用了我找到的代码,但是代码要求我在我要求的'th'标题中添加'id'标签,我试图这样做,但由于某种原因无法实现。我对编码非常陌生并正在努力解决这个问题,因为我正在尝试学习。



Hello,

I am attempting to sort my search results in two columns (Name and Price) by ascending and descending options. I have used a code I found but the code requires me to add an 'id' tag to the 'th' headings I require, I have attempted to do this but have not been able to for some reason. I am very new to coding and am struggling with this issue as I am trying learning on the fly.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Jenewan Pets</title>
    <link rel="icon" type="image/gif/png" href="img/Logo.png"/>
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  </head>
  <body>
    <body background="img/bckgrnd.png">
    <div id="container">
        <div id="header">
          <img src="img/Header.png" style="position: absolute; top: 0px;"/>
          <h1>
          <img src="img/logo.png" alt="logo" height="100px" width="100px"  border="0px" style=position:relative; />
          <div class="box">
            <div class="container-1">
                <form method="get" action="searchresults11.php" id="searchForm">
                <input type="text" id="searchBox" name="query" placeholder="Let's Sniff it Out...">
                  <div class="search-icon">
                    <img class="search-icon" img src="img/PawSearch.png" width="18" height="18" alt="search icon" />
                  </div>
            </div>
          </div>
        </h1>
    </div>
<div id="content">
      <div id="nav">
      <ul>
              <li><a class="selected" href="/index.php">Home</a></li>
              <li><a href="dogs.php">Dogs</a></li>
              <li><a href="">Cats</a></li>
              <li><a href="birds.php">Birds</a></li>
              <li><a href="">Reptiles/Exotic</a></li>
              <li><a href="">Aquatics</a></li>
          </ul>
        </div>
      <div id="Results">
        <h2>We sniffed and we found...</h2>
        <?php
        $con=mysqli_connect("localhost","root","","catalog");
        // Check connection
        if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }

        if(isset($_GET['query'])){
          $searchq = $_GET['query'];
          }
        $query = mysqli_query($con,"SELECT * FROM final_dog_catologue_full where
        keywords LIKE '%$searchq%' OR brand LIKE '%$searchq%' OR name LIKE '%$searchq%' LIMIT 0, 40") or
        die(mysqli_error("Sorry we lost the scent..."));

        echo "<table border='2'>
       <tr>
       <th>  </th>
       <th id="Name">Item Name</th>
       <th>Brand</th>
       <th id="Price">Price</th>
       </tr>";

        while($row = mysqli_fetch_array($query))
        {
        echo "<tr>";
        echo "<td><img src='img/".$row['Picture']."'></td>";
        echo "<td>" . $row['Name'] . "</td>";
        echo "<td>" . $row['Brand'] . "</td>";
        echo "<td>£" . $row['Retail_Price_With_Delievery'] . "</td>";
        echo "</tr>";
        }
        echo "</table>";


        mysqli_close($con);
?>
<script>

var table = $('table');

   $('Names, Price_Header')
       .wrapInner('<span title="sort this column"/>')
       .each(function(){

           var th = $(this),
               thIndex = th.index(),
               inverse = false;

           th.click(function(){

               table.find('td').filter(function(){

                   return $(this).index() === thIndex;

               }).sortElements(function(a, b){

                   return $.text([a]) > $.text([b]) ?
                       inverse ? -1 : 1
                       : inverse ? 1 : -1;

               }, function(){

                   // parentNode is the element we want to move
                   return this.parentNode;

               });

               inverse = !inverse;

           });

       });
       </script>

       </div>
    </div>
    <div id="footer">
        Copyright © 2017 Jenewan Pets

    <!-- jQuery first, then Tether, then Bootstrap JS. -->
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>



  </body>
</html>





我的尝试:



我有尝试在表头id标签上使用单引号以及双引号。我试过改变它从SQL数据库中读取的方式。但不幸的是,我现在的技能有限,因为我仍在学习代码的不同方面。我有一个Javascript选项,我似乎无法工作,我不确定为什么。



What I have tried:

I have tried using single quotation marks on the table header 'id' tags as well as double quotation marks. I have tried changing the way it reads from the SQL database. But unfortunately my skill is limited for now as I am still learning the different aspects of the codes. I have a Javascript option that I cannot seem to get working and am unsure why.

推荐答案

con = mysqli_connect( localhost root 目录);
// 检查连接
if (mysqli_connect_errno())
{
echo < span class =code-string>无法连接到MySQL:。 mysqli_connect_error();
}

if(isset(
con=mysqli_connect("localhost","root","","catalog"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if(isset(


_GET [' query'])){
_GET['query'])){


searchq =
searchq =


这篇关于无法使此代码正常工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆