Forums

[resolved] Loop almost right but not quite (5 posts)

  1. celine22b
    Member
    Posted 1 year ago #

    Hi,

    I'm new to all this so any help is greatly appreciated.

    I'm trying to return the contents of a table but my code captures everything but the first row.

    Below is a simple version of the code which

    produces 23456789 when it should produce 123456789.

    Thanks for your help.

    <?php
    
    require_once("mysqli_connect.php");
    
        $check_query = 'SELECT * FROM products';
        $result = mysql_query($check_query, $connection) or die(mysql_error());
        $row = mysql_fetch_assoc($result)
    ?>
    <html>
        <head>
            <title>Title</title>
        </head>
        <body>
            <?php
            while ($qdata = mysql_fetch_array($result, MYSQL_ASSOC)) {
                foreach($qdata as $key => $value) {
                    if($key =='item'){
                       echo $value.',<br />';
                    }
                }
            }
            ?>
        </body>
    </html>
  2. vtxyzzy
    Member
    Posted 1 year ago #

    You are throwing away the first row with $row = mysql_fetch_assoc($result).

  3. celine22b
    Member
    Posted 1 year ago #

    Solved, merci buckets.

  4. vtxyzzy
    Member
    Posted 1 year ago #

    I think that is murky buckets, or maybe donkey shins. Anyway, please use the dropdown at top right to mark this topic 'Resolved'.

  5. celine22b
    Member
    Posted 1 year ago #

    but of course ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags