Page 1 of 1

Pull Data from a table into an array

Posted: 2019-08-23 11:01
by bescott53
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;
								}

Re: Pull Data from a table into an array

Posted: 2019-08-28 13:36
by pbottcher
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;
}

Re: Pull Data from a table into an array

Posted: 2019-08-30 10:25
by bescott53
works like a dream! thank you

Re: Pull Data from a table into an array

Posted: 2019-09-04 07:34
by onoehring
Hi pbötcher,

nice solution.

Olaf

Re: Pull Data from a table into an array

Posted: 2019-09-04 08:28
by jsetzer
An alternative one-liner:

Code: Select all

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