Mysql results listing twice

Discussion in 'MySQL' started by Kain, Aug 1, 2008.

  1. #1
    The query below is listing the results twice.

    It should give the results like this:
    John
    Smith
    35


    Instead its giving:
    John
    John
    Smith
    Smith
    35
    35

    Any ideas?

    <?php

    $conn=mysql_connect ("localhost", "xxxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ('xxxxx', $conn);


    $result=mysql_query("SELECT * FROM xxxxx");
    while ($data=mysql_fetch_array($result)) {

    foreach ($data as $field)
    echo "$field <br>";


    }
    mysql_close($conn);
    ?>
     
    Kain, Aug 1, 2008 IP
  2. Kain

    Kain Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Fixed it

    I changed mysql_fetch_array to mysql_fetch_assoc
     
    Kain, Aug 1, 2008 IP