2016-05-10 28 views
-3

我不斷收到:查詢不起作用。介意看看它?

警告:mysqli_fetch_assoc()預計參數1被mysqli_result,布爾在

給我列在下面討論的SQL,我想知道什麼即時做錯了( $狀態是一個字符串,只是說:「表單提交)

$sql= "SELECT * FROM `veggie` ORDER BY `buy_date` desc LIMIT 20 OFFSET 0 WHERE `status` = '$status' "; 

編輯:可以做線50和84

<?php 
require_once $_SERVER['DOCUMENT_ROOT'].'/system/init.php'; 
if (!is_logged_in()) { 
    login_error_redirect(); 
} 
include 'includes/head.php'; 
include 'includes/navigation.php'; 

$page=''; 
$status = "Form Submitted"; 
if (!isset($_GET['page'])){ 
    $sql= "SELECT * FROM `veggie` ORDER BY `buy_date` desc LIMIT 20 OFFSET 0 WHERE `status` = '$status' "; 
} 

if(isset($_GET['page'])){ 
    $page = $_GET['page']; 
    $offset = 20 * $page; 
    $sql= "SELECT * FROM veggie ORDER BY buy_date desc LIMIT 20 OFFSET $offset WHERE `status` = '$status' "; 
} 
$result = $db->query($sql); 

$p = $page; 

?> 


<h2 class="text-center">Veggie Crate Forms</h2><hr> 

<table class= "table table-bordered table-striped table-auto"> 
<thead> 

    <th class="info">Full_Name</th> 
    <th class="info">email</th> 
    <th class="success">crate</th> 
    <th class="active"># people</th> 
    <th class="active">Products</th> 
    <th class="active">Bulk Items</th> 
    <th class="active">Interests</th> 
    <th class="active">How did you find us?</th> 
    <th class="active">Are you ready?</th> 
<!-- <th class="danger">Delete</th> --> 

</thead> 
<tbody> 
    <?php 


    ?> 

    <?php while($archived = mysqli_fetch_assoc($result)) : ?> 

     <?php 
     $full_name = $archived['first'].' '.$archived['last']; 
     ?> 
    <tr> 

     <td><?=$full_name?></td> 
     <td><?=$archived['email']?></td> 
     <td><?=$archived['crate']?></td> 
     <td><?=$archived['people']?></td> 
     <td><?=$archived['bulk']?></td> 
     <td><?=$archived['class']?></td> 
     <td><?=$archived['how']?></td> 
     <td><?=$archived['ready']?></td> 
     <!-- <td><a href="archived.php?delete=<?=$archived['id']?>"><span class="glyphicon glyphicon-minus">Delete</span></a></td> --> 
    </tr> 
    <?php endwhile; ?> 
</tbody> 
</table> 


<div id="decrease" style="" class=""> 


<?php if ($page > 0): ?> 
    <form class="form" action="whf.php?page=<?=--$p?> " method="post"> 
    <input type="submit" name="name" value="<--"> 
<?php endif; ?> 

    </div> 

    <div id="increase" class=""> 

    <?php $countr = mysqli_num_rows($result); 

    if($countr == 10){ 


    if ($page == '' || $page < 1): ?> 
     <form class="form" action="whf.php?page=1 " method="post"> 
     <input type="submit" name="name" value="-->"> 
    <?php endif; ?> 

    <?php 

    if ($page < $countr && $page != '' && $page != 0): ?> 
     <form class="form" action="whf.php?page=<?=++$p?> " method="post"> 
    <input type="submit" name="name" value="-->"> 
    <?php endif; 

} ?> 


    </div> 



<?php include 'includes/footer.php'; ?> 
+0

請發表您的其他代碼,特別是產生該警告的行 – Pevara

+0

您是否已經迴應了您的sql並直接在mysql上運行它?我將確保它在針對mysql運行時確實返回了一些結果 – xJoshWalker

+0

在查詢中有語法錯誤 –

回答

0

1st。 WHERE子句出現在ORDER子句之前

第2個。閱讀警告,你給它一個錯誤的參數。

$link = mysqli_connect("localhost", "username", "password", "database"); 
$result = mysqli_query($link, $sql) 
$row = mysqli_fetch_assoc($result); 

3rd。爲什麼你使用面向對象然後切換到程序? 如果你開始

$res = $db->query($sql); 

那麼就應該是:

$row = $res->fetch_assoc(); 

檢查手冊 http://php.net/manual/en/mysqli-result.fetch-assoc.php

0

您有多個語法錯誤。 您的查詢應該是這樣的:

SELECT * FROM `veggie` WHERE `status` = "$status" ORDER BY `buy_date` desc LIMIT 20 OFFSET 0 

ORDER BY,LIMIT和OFFSET在查詢的末尾去。