Jump to content

Quick Function Edit


unemployment

Recommended Posts

How can I make this function say if $id is a set parameter, use it.  If not, use globals $user_info['uid']?

 

function fetch_user_info_by_id()
{
global $user_info;

$sql =	"SELECT 
			`users`.`id`,
			`users`.`firstname`, 
			`users`.`lastname`, 
			`users`.`username`, 
			`users`.`email`,
			`users`.`gender`, 				
			`users`.`accounttype`,
			`users`.`personalweb`,
			`users`.`guestviews`,
			`users`.`iviews`,
			`users`.`eviews`,
			`users`.`credentials`,
			`users`.`specialties`,
			`users`.`country`, 
			`users`.`city`, 
			`users`.`state`, 
			`users`.`phonenumber`,
			`users`.`dateofbirth` AS `dob`,
			`iQuestions`.`investortype`,
			DATE_FORMAT(`users`.`dateofbirth`,'%D \of %M %Y') AS `dateofbirth`,
			DATE_FORMAT(`users`.`signupdate`,'%D %M %Y') AS `signupdate`,
			SUM(`companies`.`capitalrequested`) AS `totalrequested`,
			SUM(`iQuestions`.`capitalavailable`) AS `totalavailable`
		FROM `users` 
		LEFT JOIN `companies`
		ON `users`.`id` = `companies`.`adminid`
		LEFT JOIN `iQuestions`
		ON `users`.`id` = `iQuestions`.`userid` 
		WHERE `users`.`id` = '${user_info['uid']}'";

$result = mysql_query($sql);

return mysql_fetch_assoc($result);
}

Link to comment
https://forums.phpfreaks.com/topic/236463-quick-function-edit/
Share on other sites

Not sure what you mean but change

function fetch_user_info_by_id()
{
global $user_info;

to

function fetch_user_info_by_id($id = null)
{
global $user_info;

if(is_null($id))
	$id = $user_info['uid'];

 

Next change

			WHERE `users`.`id` = '${user_info['uid']}'";

to

			WHERE `users`.`id` = '$id'";

Link to comment
https://forums.phpfreaks.com/topic/236463-quick-function-edit/#findComment-1215700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.