I have two tables: one called scripts and hold script_name and the called users and holds user_id, im trying to create multidimensional array that will assign each of the script names to every existing user , for example: if i have two users [user_id:1, user_id:2] and two scripts [script_id:5,script_id:6] the array will look something like :
[
(user_id:1,script_id:5),
(user_id:1,script_id:6),
(user_id:2,script_id:5),
(user_id:2,script_id:6)
]
the problem is that the array im creating holds only the last user (user 2) and in it all scripts as i want:
[
(user_id:2,script_id:5),
(user_id:2,script_id:6)
]
this is my code:
//Create an array
$json_response = array();
//get all users
$usersResult = mysql_query("select user_id from users");
while ($row = mysql_fetch_array($usersResult, MYSQL_ASSOC)) {
$row_array['user_id'] = $row['user_id'];
}
//get all script name's and cron format's
$scriptsResult = mysql_query("select script_name from scripts");
while ($row = mysql_fetch_array($scriptsResult, MYSQL_ASSOC)) {
$row_array['script_name'] = $row['script_name'];
array_push($json_response,$row_array);
}
echo json_encode($json_response);
whileiteration overwrites$row_array[KEY]value in usersResultwhileloop. What did you expect?