Jump to content

[SOLVED] help w/function array


sandrob57

Recommended Posts

This function is not spitting out an array...*grumble* What's wrong with it!

 

<?php

function get_minerals($user_id)
{
if (iMEMBER){

	$userminerals = dbquery("
	SELECT * FROM fusion_minerals 
	WHERE user_id='$user_id'");

		if (dbrows($userminerals) == 0){

			dbquery("INSERT INTO fusion_minerals (user_id) VALUES('".$user_id."')");

				$userminerals = dbquery("
				SELECT * FROM fusion_minerals 
				WHERE user_id='$user_id'");

			$userminerals = array($userminerals);

		}else{

			$userminerals = array($userminerals);

		}

	return $userminerals;
}
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/45974-solved-help-wfunction-array/
Share on other sites

Oops, the function should have been dbarray();

 

Either way, it still isn't working.

 

<?php

function get_minerals($user_id)
{
if (iMEMBER){

	$userminerals = dbquery("
	SELECT * FROM fusion_minerals 
	WHERE user_id='$user_id'");

		if (dbrows($userminerals) == 0){

			dbquery("INSERT INTO fusion_minerals (user_id) VALUES('".$user_id."')");

				$userminerals = dbquery("
				SELECT * FROM fusion_minerals 
				WHERE user_id='$user_id'");

			$userminerals = dbarray($userminerals);

		}else{

			$userminerals = dbarray($userminerals);

		}

	return $userminerals;
}
} 

?>

Are you sure that iMEMBER is set and that it is even entering that first if statement?

Im 100% sure iMEMBER is set. Also:

 

                $userminerals = dbquery("

SELECT * FROM fusion_minerals

WHERE user_id='$user_id'");

 

 

brings no errors when I run it on a blank page.

See it helps to post the whole code, You are not setting $userminerals to be anything outside the scope of the function, sure you are returning it, but returning it to where? Try this man.

 

<?php

include "!get_minerals.php";

$userminerals = get_minerals($userdata['user_id']); // note i am setting the variable $userminerals to the return statement of the function.

print_r ($userminerals);

 

If you do not want to have to do the $userminerals = part make sure to make $userminerals a global variable inside the function definition.

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.