Jump to content

Double Print On Foreach Array


mobone
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...