1

What is the problem with my code?

$sql = "select username,num from login order by num desc";
$result = $conn->query($sql);
$rnk=1;
if ($result->num_rows > 0) {
    while($row = mysqli_fetch_array($result)){
        echo "<tr><td>";
        echo $row["username"];
        echo "</td><td>";
        echo $row["num"];
        echo "</td><td>";
        echo $rnk;
        echo "</td></tr>"
    }
} else {
    echo "0 results found";
}
$conn->close();

I had placed the above code after providing necessary connection codes between table element in my html page with .php extension. When i call the page it shows only a blank page. Its not even showing the table headers.

3
  • 1
    Tyyypooooooooo:) echo "</td></tr>" Commented Jun 22, 2015 at 5:08
  • even echo "<tr><td>" . $row["username"]. "</td><td>" . $row["num"]. " " . $rnk. "</td></tr>"; doesnt works Commented Jun 22, 2015 at 5:11
  • @Hanky웃Panky is trying to say that you forgot ; on that line. Commented Jun 22, 2015 at 5:13

2 Answers 2

1

Try this one

$sql = "select username,num from login order by num desc";
$result = $conn->query($sql);
$rnk=1;
if ($result->num_rows > 0) {
 echo "<table>";
 while($row = mysqli_fetch_array($result)){
 echo "<tr><td>".($row['username'])."</td>";
 echo "<td>".($row['num'])."</td>";
 echo "<td>".($rnk)."</td></tr>";
 }

    echo "</table>";
} else {
    echo "0 results found";
}
$conn->close();
Sign up to request clarification or add additional context in comments.

Comments

0

Crank up PHP error reporting so you can see what the real problem is.

http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

Also look in the Apache error.log to see what, if any, errors are being logged. Assuming you are using Apache

Comments

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.