检查链接设置的URL是否设置

时间:2016-01-13 06:49:01

标签: php

试图解决这个问题几天,只是不知道我做错了什么。

在if语句中,我正在设置if $_GET['orderBy'],这是我点击链接的时候。而且我还在检查等于orderBy的值是否等于数组$orderBy中的值,这也是真的。

但if语句没有被执行,为什么会这样?

echo "<table class='table table-hover table-condensed'>
              <tr>
                  <th></th>
                  <th><a href='?orderBy=service_id'>#</a></th>
                  <th><a href='?orderBy=efternamn'>Efternamn</a></th>
                  <th><a href='?orderBy=fornamn'>Förnamn</a></th>
                  <th><a href='?orderBy=datum'>Datum</a></th>
                  <th><a href='?orderBy=reg_av'>Registrerat av</a></th> 
              </tr>";

$orderBy = array('service_id', 'efternamn', 'fornamn', 'datum' ,'reg_av');
$order = 'datum';

if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
    $order = $_GET['orderBy'];
    echo "Order by ". $order;
}else{

    echo "Order by ". $order;
} 


$query = 'SELECT service.*, kunder.fornamn, kunder.efternamn 
        FROM service_test 
        JOIN kunder ON service.kund_id=kunder.id 
        WHERE service.utford_datum != 0000-00-00
        ORDER BY '.$order;

$result = $connect->query($query);
mysqli_close($connect); 

if(mysqli_num_rows($result) == 0){
    echo"No posts found";
}else{ 

    while($result_rs=mysqli_fetch_assoc($result)){
        echo "<tr>
                <td>
                    <form action='service_open.php' method='GET'>
                        <input type='hidden' name='vill_editera_service' value='1'>
                        <input type='hidden' name='service_id' value='" . $result_rs['service_id'] . "'>
                        <input type='hidden' name='kund_id' value='" . $result_rs['kund_id'] . "'>
                        <input type='submit' class='btn btn-danger btn-sm' value='Öppna'>
                    </form>
                </td>
                <td>" . $result_rs['service_id'] . "</td>
                <td>" . $result_rs['efternamn'] . "</td> 
                <td>" . $result_rs['fornamn'] . "</td>
                <td>" . $result_rs['datum'] . "</td> 
                <td>" . $result_rs['reg_av'] . "</td>
            </tr>";
    }
    echo "</table> \n";

}

编辑: 也通过运行此代码进行测试:

$testing = $_GET['orderBy'];
echo $testing;'

但它也不起作用。我收到错误消息: 注意:未定义的索引:

orderBy in /Applications/XAMPP/xamppfiles/htdocs/VP-projekt/include/inc.servicelist.php on line 17

问题可能在XAMPP内吗?

编辑#2:编辑#2: 这是html代码

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start(); ?>

<!DOCTYPE html>
<head>

<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="css/my_css.css" type="text/css" />

<script type="text/javascript" src="js/jquery-1.11.3.min.js"> </script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script> 
 <script type="text/javascript" src="js/bootstrap.js"> </script>
<script type="text/javascript">

$(document).ready(function() {

    $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "include/inc.servicelist.php",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $("#pagaende").html(response); 
            //alert(response);
        }
    });

    $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "include/inc.garantiservice.php",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $("#garanti").html(response); 
            //alert(response);
        }
    });
 $('#myTabs a:first').tab('show');
    $("#sortedtable").tablesorter({ sortlist: [0,0] });

});
</script>

</head>

<body>
<?php if (login_check($mysqli) == true) : ?>
<?php include("include/inc.menu.php") ?>
<div class="row">
    <h1 class="text-center">Pågående arbetsordrar</h1>
</div> <!-- row -->


<div id="myTabs" class="col-md-6 col-md-offset-3">

<ul class="nav nav-tabs" role="tablist">
<li role="presentation"><a href="#bokade" aria-controls="home" role="tab" data-toggle="tab">Bokade</a></li>
<li role="presentation"><a href="#garanti" aria-controls="profile" role="tab" data-toggle="tab">Garanti</a></li>
</ul>


<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="bokade">
    <div id="pagaende" align="center"></div>
</div>
<div role="tabpanel" class="tab-pane" id="garanti"></div>
    <div id="garanti" align="center"></div>
</div>

</div>
<?php else : ?>
    <p>
        <span class="error">You are not authorized to access this page.         </span> Please <a href="index.php">login</a>.
    </p>
<?php endif; ?>

</body>

</html>

2 个答案:

答案 0 :(得分:0)

你不能只使用

in_array()

我怀疑您的true条件返回false。确保返回值echo

此外,在设置table的值后,尝试$order for(int i(9), j(0); i > j; i--, j++) cout << i; {/ 1}}。

答案 1 :(得分:0)

我复制了你的数据库和代码:

&amp;gt;

并且它有效...(将tablename更改为service,将datum列名更改为datum并添加了一些检查)