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
Veteran Member
Posts: 134
Joined: 2013-02-24 00:13

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;
								}
Appgini 5.72

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 553
Joined: 2018-04-01 10:12

Re: Pull Data from a table into an array

Post by pböttcher » 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;
}

bescott53
Veteran Member
Posts: 134
Joined: 2013-02-24 00:13

Re: Pull Data from a table into an array

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

works like a dream! thank you
Appgini 5.72

onoehring
Veteran Member
Posts: 263
Joined: 2019-05-21 22:42
Contact:

Re: Pull Data from a table into an array

Post by onoehring » 2019-09-04 07:34

Hi pbötcher,

nice solution.

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 238
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;

Post Reply