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>
  • 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`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Mar 05 '17 at 00: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! –  Mar 05 '17 at 00:36

1 Answers1

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.

Maarten van Middelaar
  • 1,691
  • 10
  • 15