Jump to content

Double Print On Foreach Array


mobone

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...