php array return
Ok, function:
function session_login_name($username) {
global $myDB;
global $config;
$query = "SELECT /* page == login, functions.php */id, username FROM members WHERE username = '".$username."' LIMIT 1";
$result = $myDB->Execute($query) or die(GetDbError($myDB->ErrorMsg()));
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr = array($nick_show, $nick_id);
return $arr;
}
In next file i need describe:
$_SESSION['userid'] = ; //user id
$_SESSION['username'] = ; //user name
How do I do that? If question unclear, just s开发者_如何学编程ay it... Oh, and print_r ($arr) gives: Array ( [0] => zero [1] => 4 )
I have tried (guessed), but that of course isn't correct :/
echo session_login_name($username[0]);
die();
You said print_r ($arr) gives: Array ( [0] => zero [1] => 4 )
so you just need to get those value and assign them to the session variables:
// ToDo: fix SQL injection vulnerability in your SQL
$Data = session_login_name($username);
$_SESSION['userid'] = $Data[1]; //user id
$_SESSION['username'] = $Data[0]; //user name
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr['userid'] = $nick_id; //user id
$arr['username'] = $nick_show; //user name
return $arr;
well you cant echo an array it will print array() on the screen
where did you define $username ?
well simply read the values of the array
精彩评论