Why the PHP output is not displaying on webpage?

1.2k views Asked by At

I am not getting any output from this php code shows blank page

 <?php
include 'conn.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include('callheadcss.php');?>
</head>
<body>

Div to show php Output

<div id="slidey">
<ul>
<?php

working with prepare statement

$stmt = $con->prepare('SELECT * FROM sliderimg');

$stmt->execute();
$result = $stmt->get_result();
$numRows = $result->num_rows;
if($numRows > 0)
{
while ($row = $result->fetch_assoc())
{
$imgpath=$row['SliderImg'];
echo '<li><img src="'.$imgpath.'"><p class="title">'. $row['Event_name'] .'</p><p class="description">'. $row['Eventdate'] .'</p></li>';    
}
}
?>
</ul>       
    </div>
</body>

script for slider

<script src="designcss/js/jquery.slidey.js"></script>
    <script src="designcss/js/jquery.dotdotdot.min.js"></script>
       <script type="text/javascript">
            $("#slidey").slidey({
                interval: 8000,
                listCount: 5,
                autoplay: false,
                showList: true
            });
            $(".slidey-list-description").dotdotdot();
        </script>
3

There are 3 answers

3
Frankich On BEST ANSWER
$stmt->execute();
$result = $stmt->get_result();
$result->store_result();
$numRows = $result->num_rows;

by php.net :

Returns the number of rows in the result set. The use of mysqli_stmt_num_rows() depends on whether or not you used mysqli_stmt_store_result() to buffer the entire result set in the statement handle.

If you use mysqli_stmt_store_result(), mysqli_stmt_num_rows() may be called immediately.

php.net

5
syl.fabre On

Quick suggestions:

  • add some dummy text like lorem ipsum right after the <body> tag: if it does not show then your problem is not related to your PHP script
  • use var_dump($numRows) to be sure that there is a least a row to be used
2
Akhil On

try to print $row using

print_r($row);

This will print $row in array format so you can see all data are coming or not