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 Link to comment https://forums.phpfreaks.com/topic/122090-hi-a-simple-question/ 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. Link to comment https://forums.phpfreaks.com/topic/122090-hi-a-simple-question/#findComment-630382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.