Как изменить порядок всей инструкции SQL в порядке убывания? [Дубликат]

0

У меня есть этот код, и я хочу отображать данные в порядке убывания. Я использовал ORDER BY postID. Но это не сработало, показывая ошибку. Пожалуйста, помогите мне исправить это.

Предупреждение: mysqli_num_rows() ожидает, что параметр 1 будет mysqli_result, boolean задан в C:\xampp\htdocs\mysite\category.php в строке 13

Вот мой код '$ post_sql = "SELECT post.postID, post.head, post.author, post.date, post.content1, post.content2, post.content3, post.image, post.figure1, post.figure2, post.figure3, post.link1, post.link2, category.name AS catname FROM post order by postID JOIN category ON post.categoryID = category.categoryID WHERE post.categoryID = ". $ _ GET ['categoryID'];

if ($post_query=mysqli_query($dbconnect,$post_sql)) {
    $post_rs=mysqli_fetch_assoc($post_query);
}
if (mysqli_num_rows($post_query)==0) {
    echo "Not Found !!! ";
}else{
    ?>
    <h1><?php echo $post_rs['catname']; ?></h1>

    <div class="col-md-8">
        <?php
        if($_GET['categoryID']==4){
            ?>
            <h4> &nbsp Upload your project and Events ... share the experience</h4>
            <h5> &nbsp &nbsp &nbspThis area is for you to share your projects with others. You can upload some photos videos and related documents of your project. Also help others to make it!!<br><br>
             &nbsp &nbsp &nbsp Also let us know about the events and exhibitions in your school or university. Just click below!!</h5>
            <a href="index.php?page=addyours"><button>Upload yours</button></a>
            <br><hr>
            <?php
        }
    ?>
    <?php do{
            ?>
            <div class="col-md-6">
                <div class="post">
                    <a class="post-img" href="index.php?page=post&postID=<?php echo $post_rs['postID'];?>"><img src="admin/images/<?php echo $post_rs['image'];?>" alt="" width=400 height=275></a>
                    <div class="post-body">
                        <div class="post-category">
                            <a href="#"><?php echo $post_rs['catname']; ?></a>
                        </div>

                        <h3 class="post-title">
                            <a href="index.php?page=post&postID=<?php echo $post_rs['postID'];?>">
                            <?php echo $post_rs['head']; ?></a></h3>
                        <ul class="post-meta">
                            <li><a href="author.php"><?php echo $post_rs['author']; ?></a></li>
                            <li><?php echo $post_rs['date']; ?></li>
                        </ul>
                        <p><?php echo $post_rs['content1']; ?></p>
                    </div>
                </div>
            </div>
    <?php
    }while($post_rs=mysqli_fetch_assoc($post_query));
    ?>
    </div>
    <?php
}

?>"

Теги:

2 ответа

0
Лучший ответ

Поскольку ошибка говорит о том, что выполнение запроса не выполняется, а порядок по условию должен после этого условия

$post_sql="SELECT post.postID, post.head, post.author, post.date, post.content1, post.content2, post.content3, post.image, post.figure1, post.figure2, post.figure3, post.link1, post.link2, category.name AS catname FROM post order by postID JOIN category ON post.categoryID=category.categoryID WHERE post.categoryID=".$_GET['categoryID'];

Измените это так, как это

$post_sql="SELECT post.postID, post.head, post.author, post.date, post.content1, post.content2, post.content3, post.image, post.figure1, post.figure2, post.figure3, post.link1, post.link2, category.name AS catname FROM post  JOIN category ON post.categoryID=category.categoryID WHERE post.categoryID=".$_GET['categoryID']."order by postID desc";
  • 0
    Это сработало. большое Вам спасибо.
0

Я не знаю PHP, но кажется, что вам нужно написать if (mysqli_num_rows($post_rs)==0) { в строке 4 показанного кода (или строки 13 файла), чтобы удалить предупреждение. Кроме того, order by clause обычно приходит в конце запроса, а не до соединения.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню