Pull Data from a table into an array

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
bescott53

Pull Data from a table into an array

Post by bescott53 » 2019-08-23 11:01

Hi Board!

I am trying to pull all entries from a table into an array and restrict the access of the CSV download to this array.
here is what i have but its not working, anyone no why?

Code: Select all

function access_init(&$options, $memberInfo, &$args){

                                $sql_csvusers = array(sql("select `id` FROM `csv_allowed`"));
                                  if(in_array($memberInfo['username'], $sql_csvusers)){
								   $options->AllowCSV=1;
									}else{
								   $options->AllowCSV=0;
									}

                                return TRUE;
								}

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Pull Data from a table into an array

Post by pbottcher » 2019-08-28 13:36

Hi,

try

Code: Select all

function access_init(&$options, $memberInfo, &$args){
	$res = sql("select `id` FROM `csv_allowed`",$eo);
	while($row = db_fetch_row($res)) {
		$sql_csvusers[]=$row[0];
	}
	if(in_array($memberInfo['username'], $sql_csvusers)){
		$options->AllowCSV=1;
	}else{
		$options->AllowCSV=0;
	}
        return TRUE;
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

bescott53

Re: Pull Data from a table into an array

Post by bescott53 » 2019-08-30 10:25

works like a dream! thank you


User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Pull Data from a table into an array

Post by jsetzer » 2019-09-04 08:28

An alternative one-liner:

Code: Select all

$options->AllowCSV = sqlValue("SELECT count(*) FROM csv_allowed WHERE id='{$memberInfo["username"]}'") > 0;
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply