0

my code is not displaying the first result in the while loop.

my query is working right on phpmyadmin but somethings going wrong on index page.

I have the following code:

<?php
$test=mysql_query("SELECT * FROM newsites");
$deneme=mysql_fetch_row($test);
?>
<div class='container'>
    <div class='row'>
        <?php
        while ($deneme=mysql_fetch_assoc($test)) {
            extract($deneme);
            echo '<div class="col-md-3 col-sm-6 col-xs-12 back-colour">';

            echo '<td><img class="img-responsive" src="images/'.$deneme['site_pic'].'" width="120" height="20"/></td>';
            echo '<p class="box-design">'.$deneme['site_name'].'</p>';
            echo '<p class="box-design">'.$deneme['site_link'].'</p>';
            echo '<p class="box-design">'.$deneme['site_ref'].'</p>';
            echo '<p class="box-design">'.$deneme['site_type'].'</p>';

            echo '</div>';
        }
        ?>
    </div>
</div>
2
  • 1
    If you're writing new code, please don't use the mysql_* functions. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use PDO or mysqli_* with prepared statements and parameter binding instead. See stackoverflow.com/q/12859942/354577 for details. Commented Mar 5, 2017 at 0:33
  • that's mine first project about php so i did not know anything about mysqli or pdo. i'll use them if i keep working on php. thanks for response! Commented Mar 5, 2017 at 0:36

1 Answer 1

5

It looks like the first row is already taken from the resultset outside the while loop.

On line 3 you have $deneme=mysql_fetch_row($test);

I'd say remove it and you're good to go.

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

Comments

Your Answer

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