Assigning Global Variable to an array from a recordset

I’m having trouble getting this to work and if anyone can help, it would be greatly appreciated.

I’m trying to establish a global variable of an array of numbers which represent counties an agent works in. These can be obtained by a select statement and will produce one or more rows, each row with only one number. I can then use the “implode” function to change the recordset to a string which I can use in WHERE clauses to list the counties or whatever.

Being new to SC (using SC 7.1 on a Mac) I’m a little stumped about how to code this. I’ve been trying the following and while I don’t get any blank screens or errors, I also don’t create the variable to convert to a string. I’m putting this in the sec_Login app, created in the Security module because there are a number of other global session variables created here. I’ve been trying to write this with a combination of the macros and what PHP I know, but it’s not working.


$sql_area = "SELECT
   coid County
FROM
   agentarea
WHERE 
   (uid = ". [uid] .")
ORDER BY
   coid";

sc_lookup(rs, $sql_area);


$agent_area = array();
$row_rs = "";

if (count({rs}) !== 0)
	{

while ($row_rs = mysql_fetch_assoc({rs}))
	{
		$agent_area[] = $row_rs[{County}];
	}
sc_set_global($agent_area);
}

Again, excuse my ignorance and inexperience. Hopefully one of you old-timers can at least point me in the right direction.

Hi,
if I’m getting this right, you need a comma (or whatever) separated list of numbers. Here is a little two-liner.

$sql_area = “SELECT
County
FROM
agentarea
WHERE
(uid = “. [uid] .”)
ORDER BY
coid”;

sc_lookup(rs, $sql_area);
if(count({rs}) !== 0)
{
$counties = array_map(function($item) { return $item[0]; } , $rs); //$counties is one dimensional array of your select
[agent_area] = impolde(’,’,$counties); // [agent_area] is the comma separated list as a global variable
}

Hope this helps.

jsb

There is no substitute for knowledge. Thanks so much. Worked like a charm.

I’d better bone up on array_map…I’d missed the boat on this one.

This part is working fine. Not getting password retrieval email alone. But got error while trying to use the feature.

I am using this above code and its work good. but after one time run its terminated.

Thanks to All

Thanks to everyone for your comments. The question was actually answered by jsbinca way back when.

Local variables defined in a form instance, usually when the form is opened. These variables persist as long as the shape remains open. These variables and constants are also known as public public and Constants variables, as they are known only to the form and subforms attached to a main form. http://www.examcollectionvce.com/vce-100-101.html

Global variables can be very difficult and problematic. It is very difficult to say whether or not to declare them as such without seeing the full code context. What you can do is declare a public function, and pass on certain arguments eliminating some duplication. http://70-332-real-exam-dumps.blogspot.com/2017/04/microsoft-70-332-question-answer.html