Home PHP while command missing first entry
Reply: 0

PHP while command missing first entry

user1848
1#
user1848 Published in April 20, 2018, 10:49 am

I am trying to use the while loop to print multiple entries from a MySQL database. Everywhere I do this it is missing the first item on the list and only manages to print from the second one on.

<?php
require 'db.php';
$udate = $mysqli->escape_string($_POST['date']);
$result = $mysqli->query("SELECT * FROM videos WHERE date='$udate'");
$user = $result->fetch_assoc();
$_SESSION['file_name'] = $user['file_name'];
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>View</title>
        <link rel="stylesheet" type="text/css" href="css/nominatorstyle.css">  
    </head>
    <body>
        <div class="header">
            <h2>Results.</h2>
            <form action="watch.php" method='POST'><table>
                <?php 
                    if($result->num_rows > 0){
                        while($row = $result->fetch_assoc()){
                            $vid = $row['vid'];                           
                            $source = "uploads/".$row['file_name'];
                            echo "<tr><td>".$row['vid']."</td>
<td>".$row['file_name']."</td>";
                            echo "<td><a href=watch.php?
source=$source>Play</a></td></tr>";
                        }
                    }else{
                    echo "0 results";
                    } 
                ?>
                </table></form>
            <a href="profile.php"><button class="button-block">Home</button></a>
        </div>      
    </body>

I'd like it to print all matching criteria. I'm getting only the entries after the first one.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.531982 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO