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: 141
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: 701
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: 141
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
AppGini Super Hero
AppGini Super Hero
Posts: 420
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
Some postings I was involved, you might find useful:
Backup your database (easy) (viewtopic.php?f=4&t=3341); Improve security / safety against DDOS and brute force (failed) logins (viewtopic.php?f=4&t=3168); Field Permissions (hide / lock fields by usergroup) (viewtopic.php?f=4&t=3308); Custom (error) message (viewtopic.php?f=7&t=1740&p=10871#p10906); Audit Log (viewtopic.php?f=4&t=1369&p=10407); Two Factor Authentication (viewtopic.php?f=7&t=3306&p=11478); Add extra (2nd) SAVE CHANGES button (viewtopic.php?f=2&t=3242&p=11104);

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