meshi Posted August 31, 2008 Share Posted August 31, 2008 I used to work with php and oracle DB, I am trying to work now with MySql, I wrote this: <?php $con = mysql_connect("localhost","work","work"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("work", $con); $result = mysql_query("SELECT * FROM users"); echo '<table border="2"> <tr><th>username</th><th>password</th><th>describe</th></tr>'; while($row = mysql_fetch_array($result)) { echo '<tr>'; foreach ($row as $user) echo '<td>'.$user.'</td>'; echo '</tr>'; } echo '</table>'; ?> each data enter to the table twice, why is that? what should I change? thanks for the hekp Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 31, 2008 Share Posted August 31, 2008 Because mysql_fetch_array returns duplicate results as it contains both a numeric array ($row[0]) and an associative array ($row['field_name']). Change mysql_fetch_array to mysql_fetch_assoc (or to mysql_fetch_row) instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.