Hi all, is there any prblem with my array? why i can get the first element of the array

function GetNameByEmail($get_staffemail)
{	print_r($get_staffemail);
	for($i=0;$i<count($get_staffemail);$i++){		
		echo "<br />";
		echo $qryGetName = "SELECT username FROM user_info WHERE email ='".$get_staffemail[$i]."'";
		$rsGetName  = mysql_query($qryGetName);
		$arrGetName[$i] = mysql_fetch_array($rsGetName, MYSQL_ASSOC);
	}
	echo "<br />";
	print_r($arrGetName);
	return $arrGetName[glob_username];
}

here the result(output)
Array ( [0] => hehe@live.com.my [1] => haha@live.com.my )
SELECT username FROM user_info WHERE email ='hehe@live.com.my '
SELECT username FROM user_info WHERE email ='haha@live.com.my'
Array ( [0] => [1] => Array ( [glob_username] => haha ) )

anyone help pls T^T this is the last task and i got to hand up by tomorrow~

Recommended Answers

All 4 Replies

I think there is no row in your database with email id "hehe@live.com.my",
if it is there then change your line number 5 in above code with following line

echo $qryGetName = "SELECT username FROM user_info WHERE trim(email) =  trim('".$get_staffemail[$i]."') ";

Is it possible yor first e-mail to be wrong? In the answer of the script first select query is:

SELECT username FROM user_info WHERE email ='hehe@live.com.my '

There is an blank space before '. Is that right?

I mean that e-mail don't have blank spaces and because of that you don't have user that response to 'hehe@live.com.my '. The solution of urtrivedi is good. Use it.

what is the name of the staffname field in table?
Are passing array to function?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.