選擇下拉列表值時如何刪除下拉列表的重復(fù)項

我對整個javascript和PHP都很陌生。我的代碼有兩個問題似乎無法修復(fù)。

當我選擇一個類別時,它應(yīng)該顯示一個具有相應(yīng)類別的表。但是它包含了一個重復(fù)的下拉列表,還有一個錯誤,我不明白為什么返回為“未定義的變量:在/var/www/html/phpDD.php第37行的輸出”,它是:“$output.=”tbody“。

希望你能幫助我繼續(xù)發(fā)展!:)

phpDD.php

<?php

    // include database connection file
    include_once "testSide.php";

    if(isset($_POST['InvestmentName']))
{
    $uid = $_POST['InvestmentName'];
}
    $qu = "select Prod.name, one.yield as yield_one, five.yield as yield_two, ten.yield as yield_three, twenty.yield as yield_four, one.stdev as st_one, five.stdev as st_two, ten.stdev as st_three, twenty.stdev as st_four, one.top1dd as top_one, five.top1dd as top_two, ten.top1dd as top_three, twenty.top1dd as top_four Select *
        from products
        where category_id = $uid) as Prod
    left join;";
        
        
            $result = $conn->query($qu);
            if (!$result) {
                trigger_error('Invalid query:' . $conn->error);
            }
        
            if ($result->rowCount() > 0) {
                $output .= "<table class='table table-hover table-border'>
                                <thead>
                                  <tr>
                                    <th>Name</th>
                                    <th>Afkast sidste ?r</th>
                                    <th>Genst sidste 5 ?r</th>
                                    <th>Genst stidste 10 ?r</th>
                                    <th>Genst sidste 20 ?r</th>
                                    <th>SR sidste ?r</th>
                                    <th>SR 5 ?r</th>
                                    <th>SR 10 ?r</th>
                                    <th>SR 20 ?r</th>
                                    <th>DD sidste ?r</th>
                                    <th>DD 5 ?r</th>
                                    <th>DD 10 ?r</th>
                                    <th>DD 20 ?r</th>
                                  </tr>
                                </thead>";
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $output .= "<tbody>
                <tr>
                  <td>{$row["name"]}</td>
                  <td>{$row["yield_one"]}</td>
                  <td>{$row["yield_two"]}</td>
                  <td>{$row["yield_three"]}</td>
                  <td>{$row["yield_four"]}</td>
                  <td>{$row["st_one"]}</td>
                  <td>{$row["st_two"]}</td>
                  <td>{$row["st_three"]}</td>
                  <td>{$row["st_four"]}</td>
                  <td>{$row["top_one"]}</td>
                  <td>{$row["top_two"]}</td>
                  <td>{$row["top_three"]}</td>
                  <td>{$row["top_four"]}</td>
                </tr>";
              
                }                       
                "</tbody>";               
                $output .= "</tbody></table>";
                echo $output;
            }else{
                echo "No records found";
            }
        ?>

Index.php

<!Doctype html>
<html lang="en">
<head>
  >
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
  <body>
    <div class="container" style="margin-top: 50px;">
      <h2 class="text-center">V?g en kategori </h2>
      <div class="row">
        <div class="col-md-4"></div>  
          <div class="col-md-4" style="margin-top:20px; margin-bottom:20px;">
            <form id="submitForm">
              <div class="form-group">
                <select class="form-control Investment" name="Investment" id="Investment">
                  <option value="">V?lg Kategori</option>
                      <?php foreach($users as $user): ?>
                        <option value="<?= $user['id']; ?>"><?= $user['name']; ?></option>
                      <?php endforeach; ?>
                </select>
              </div>
            </form>
          </div>
        </div>
        <div class="col-md-12">
          <div id="show-invest">
          </div>
        </div>    
      </div>
  </body>
</html>

<!---jQuery ajax load rcords using select box --->
<script type="text/javascript">
  $(document).ready(function(){
      $(".Investment").on("change", function(){
        var InvestmentName = $(this).val();
        if (InvestmentName !== "") {
          $.ajax({
            url : "phpDD.php",
            type:"POST",
            cache:false,
            data:{InvestmentName:InvestmentName},
            success:function(data){
              $("#show-invest").html(data);
            }
          });
        }else{
          $("#show-invest").html(" ");
        }
      })
  });
</script>
? 最佳回答:

問題是您沒有在腳本中定義$output。不能讓$output的第一個實例是$output .=,因為.=表示變量已經(jīng)存在。

要解決這個問題,請在$output .=之前添加$output = '';

For example:

<?php

    // include database connection file
    include_once "testSide.php";

    if(isset($_POST['InvestmentName']))
{
    $uid = $_POST['InvestmentName'];
}

    $output = ''; //This is required

    $qu = "select Prod.name, one.yield as yield_one, five.yield as yield_two, ten.yield as yield_three, twenty.yield as yield_four, one.stdev as st_one, five.stdev as st_two, ten.stdev as st_three, twenty.stdev as st_four, one.top1dd as top_one, five.top1dd as top_two, ten.top1dd as top_three, twenty.top1dd as top_four Select *
        from products
        where category_id = $uid) as Prod
    left join;";
        
        
            $result = $conn->query($qu);
            if (!$result) {
                trigger_error('Invalid query:' . $conn->error);
            }
        
            if ($result->rowCount() > 0) {
                $output .= "<table class='table table-hover table-border'>
                                <thead>
                                  <tr>
                                    <th>Name</th>
                                    <th>Afkast sidste ?r</th>
                                    <th>Genst sidste 5 ?r</th>
                                    <th>Genst stidste 10 ?r</th>
                                    <th>Genst sidste 20 ?r</th>
                                    <th>SR sidste ?r</th>
                                    <th>SR 5 ?r</th>
                                    <th>SR 10 ?r</th>
                                    <th>SR 20 ?r</th>
                                    <th>DD sidste ?r</th>
                                    <th>DD 5 ?r</th>
                                    <th>DD 10 ?r</th>
                                    <th>DD 20 ?r</th>
                                  </tr>
                                </thead>";
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $output .= "<tbody>
                <tr>
                  <td>{$row["name"]}</td>
                  <td>{$row["yield_one"]}</td>
                  <td>{$row["yield_two"]}</td>
                  <td>{$row["yield_three"]}</td>
                  <td>{$row["yield_four"]}</td>
                  <td>{$row["st_one"]}</td>
                  <td>{$row["st_two"]}</td>
                  <td>{$row["st_three"]}</td>
                  <td>{$row["st_four"]}</td>
                  <td>{$row["top_one"]}</td>
                  <td>{$row["top_two"]}</td>
                  <td>{$row["top_three"]}</td>
                  <td>{$row["top_four"]}</td>
                </tr>";
              
                }                       
                "</tbody>";               
                $output .= "</tbody></table>";
                echo $output;
            }else{
                echo "No records found";
            }
        ?>
Index

至于副本,在使用AJAX加載內(nèi)容時,包含了主文件testSide.php

主站蜘蛛池模板: 91在线一区二区三区| 国产乱码精品一区三上| 一区二区不卡久久精品| 亚欧色一区W666天堂| 日本精品一区二区三区视频| 精品人妻系列无码一区二区三区 | 国产一区二区三区视频在线观看| 国产一区二区三区乱码| 一区二区高清在线观看| 国产一区二区草草影院| 亚洲Av高清一区二区三区| 国偷自产一区二区免费视频| 亚洲人AV永久一区二区三区久久| 国产精品亚洲一区二区三区在线观看| 精品国产一区二区三区色欲| 精品视频无码一区二区三区| 久久99国产精一区二区三区| 国产午夜三级一区二区三| 一区三区三区不卡| 久久99精品免费一区二区| 久久久久人妻一区精品色| 精品久久一区二区三区| 国产自产V一区二区三区C| 中文字幕精品一区| 国语精品一区二区三区| 亚洲av午夜福利精品一区人妖| 国产免费无码一区二区| 久久久久久人妻一区精品| 91精品一区二区| 99久久精品午夜一区二区| 亚洲字幕AV一区二区三区四区| 国产精品亚洲午夜一区二区三区| 中文字幕一区在线观看视频| 亚洲高清一区二区三区电影| 中字幕一区二区三区乱码 | 亚州国产AV一区二区三区伊在| 精品国产一区在线观看| 日韩精品无码Av一区二区| 国产vr一区二区在线观看| 丰满少妇内射一区| 亚洲一区二区三区播放在线|