mobone Posted June 19, 2009 Share Posted June 19, 2009 Why is this printing twice?? <?php function qry($sql) { $con = mysql_connect("localhost","root","cookie"); if (!$con) die('Could not connect: ' . mysql_error()); $database = mysql_select_db("magicbattle", $con); $data = mysql_query($sql) or die(mysql_error()); return $data; }$sql="SELECT * FROM players WHERE name='mobone'";$qry = qry($sql);$player = mysql_fetch_array($qry);foreach ($player as $key => $value) { echo "Key: $key; Value: $value<br />\n";}?> Output: Key: 0; Value: 1Key: id; Value: 1Key: 1; Value: moboneKey: name; Value: moboneKey: 2; Value: cookieKey: password; Value: cookieKey: 3; Value: 25Key: health; Value: 25Key: 4; Value: 3Key: strength; Value: 3Key: 5; Value: 2Key: dexterity; Value: 2Key: 6; Value: 0Key: attacks_won; Value: 0Key: 7; Value: 0Key: attacks_lost; Value: 0 Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 When you use mysql_fetch_array it includes both named and numbered elements. If you only want the named ones, use mysql_fetch_assoc instead. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.