Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I retrieve a variable from this function?

Posted on 2014-01-31
4
Medium Priority
?
179 Views
Last Modified: 2014-01-31
Here's the code:

if (!function_exists('ptl_approlepermissionlist_byapppermissionrefuser')) {
	function ptl_approlepermissionlist_byapppermissionrefuser($apprefname,$userid) {
		global $mdb,$_SESSION;
		
		$data = array();
		$sql_data = "exec ptl_AppRolePermissionList_byAppPermissionRefUser '$apprefname', $userid";
		if ($_SESSION["portaladmin"] == 1 && $_SESSION["showsql"] != "no")
			echo display_detail("functions_db.php",$sql_data);
		$result_data = odbc_exec($mdb, $sql_data);
		
		$count = 0;
		while (odbc_fetch_row($result_data))
			{
			$count++;
			$data[$count]["appid"] = odbc_result($result_data, "appid");
			$data[$count]["apprefname"] = htmlspecialchars(odbc_result($result_data, "apprefname"), ENT_QUOTES);
			$data[$count]["permissionid"] = odbc_result($result_data, "permissionid");
			$data[$count]["permissionname"] = htmlspecialchars(odbc_result($result_data, "permissionname"), ENT_QUOTES);
			$data[$count]["permissionrefname"] = htmlspecialchars(odbc_result($result_data, "permissionrefname"), ENT_QUOTES);
			$data[$count]["roleid"] = odbc_result($result_data, "roleid");
			$data[$count]["rolename"] = htmlspecialchars(odbc_result($result_data, "rolename"), ENT_QUOTES);
			$data[$count]["rolerefname"] = htmlspecialchars(odbc_result($result_data, "rolerefname"), ENT_QUOTES);
			$data[$data[$count]["permissionrefname"]]["allow"] = true;
			}
		$data["count"] = $count;
		return $data;
		}
	}

Open in new window


I'm more accustomed to a procedural context, hence my being lost. How do I write an if statement that determines whether or not if$data[$count]["rolename"] -"developer"?

Thanks for you help!
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 400 total points
ID: 39824504
Doesn't make sense - why are you declaring a function only if another function exists.
You just have the function to start with - it's not doing any harm if the other function doesn't exist.
Remove
$data["count"] = $count;

However you call the function the values will be in that variable not in $data
0
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 1600 total points
ID: 39825036
You assign the result of the function to a variable:

$yourData = ptl_approlepermissionlist_byapppermissionrefuser($apprefname,$userid);

Open in new window

Now $yourData will be an array, containing the output from your function, and you can access the elements like so:

echo $yourData['count'];

Your array contains an array, so to loop through that, you'd use something like this:

for ($i=1; $i <= $yourData['count']; $i++) {

   //examine each element of the array
   var_dump($yourData[$i]);

   //output a specific element of the array
   var_dump($yourData[$i]['rolename'];

   //check the value:
   if ($yourData[$i]['rolename'] == 'developer'):
      echo "We have a developer";
   endif;

}

Open in new window

0
 

Author Comment

by:brucegust
ID: 39825403
Cathal!

Thanks for taking the time to weigh in. You are right, but there was some more "stuff" behind the scenes that I needed to understand in order for any of this to make sense.

BTW: This isn't my code. I'm a contract guy and I'm working right now just to get my head wrapped around what's current working / in place.

Here's what I learned:

The info I was looking for is not in the aforementioned function. Rather, it was in another stored procedure and instead of a situation where I was looking for something along the lines of $data[1]=="update" to determine if the user had the necessary permissions to update things, it was instead a two dimensional array and the resulting if statement looked like this:  if  ($appuserpermission["update"] == "developer").

Uncharted waters, major learning curve, but once I got my arms around it, I let out a big "Yes!" that un-nerved the entire floor that I'm working on.

There you have it!
0
 

Author Comment

by:brucegust
ID: 39825405
Chris, I didn't see you jumping in until after I had posted my comment. Thanks for helping out!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question