How can I add data to an associative array? Using jQuery I would like to retrieve data according to a key.
if(isset($_POST["user_name"]))
{
$sql = "SELECT * FROM users WHERE user_name='".$_POST["user_name"]."' AND user_password='".$_POST["user_password"]."'";
$result = mysql_query($sql) or die(mysql_error());
$jsonresult = array();
while($row = mysql_fetch_array($result))
{
$jsonresult["user_auth"] = 1;
$jsonresult["user_id"] = $row['user_id'];
$jsonresult["user_name"] = $row['user_name'];
$_SESSION["user_auth"] = 1;
$_SESSION["user_id"] = $row['user_id'];
$_SESSION["user_name"] = $row['user_name'];
}
echo json_encode($jsonresult);
mysql_close();
}
My problem is here :
$jsonresult["user_auth"] = 1;
$jsonresult["user_id"] = $row['user_id'];
$jsonresult["user_name"] = $row['user_name'];
There remains only the last row from the database. Why?