2

I'm trying for days now to catogorize my videos on a browsepage, but when i try. One sql gives results and the other one says it has 0 results.

    <?php
include("db-conct.php");

$cato = "SELECT * FROM movies WHERE `cato` = 'cato' ORDER BY views DESC";
$result = $conn->query($cato);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    }
}else{
echo "0 results";
}

$conn->close();
?>
<?php
$cato1 = "SELECT * FROM movies WHERE `cato` = 'cato' ORDER BY views DESC";
$result = $conn->query($cato1);

if ($result->num_rows > 0) {
    // output data of each row
    while($row1 = $result->fetch_assoc()) {
    }
}else{
    echo "0 results";
}

$conn->close();
?>

I hope someone knows what the problem is.

4
  • Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. Commented Aug 30, 2018 at 2:24
  • @Funk I'm so sorry i forgot about it. I had to wait for 10 minutes so i start coding again. I've added the solved answer and i try to remember for the next time not to edit my question. Seems logic :) Thanks Commented Sep 1, 2018 at 13:31
  • @Riggs Thank you, that's very nice :) I'm going to use it! Commented Sep 1, 2018 at 13:32
  • you're welcome @ConstantBrummer cheers Commented Sep 1, 2018 at 13:44

1 Answer 1

3

You're closing your connection after the first query:

$conn->close();

You should add error handling to your queries. http://php.net/manual/en/mysqli.error.php

Sign up to request clarification or add additional context in comments.

3 Comments

You're right man. It worked. Such a simple thing that i didnt saw. I use error handling but i tought maybe i waste ur time. Thank you so much
The error should say something more useful than your 0 results, like the connection was closed.
This is a really good one ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.