Search code examples
phpprepared-statementob-start

Why the PHP output is not displaying on webpage?


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>

Solution

  • $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