Page 1 of 1

What is the best way to filter data in hooks

Posted: 2021-01-28 05:52
by ayussuf
Hi,

I've made some filter in Hooks and it works. But I think there are other ways that are more simple using more concise code.

Any suggestion?

I code is like this

Code: Select all

	function Pelajar_init(&$options, $memberInfo, &$args) {
		
		$TableAndGroup = $memberInfo['group'];
		$RecID = sqlValue("select id FROM ".$TableAndGroup." WHERE milik = '".$memberInfo['username']."'");

		if ($TableAndGroup=="Penyelia"){
			$pelajar = sql("SELECT pelajar FROM Seliaan WHERE penyelia='{$RecID}'", $eo);
			while ($row = db_fetch_assoc($pelajar)) {
				   $array[] = $row;
			}

			$num_rows = db_num_rows($pelajar);

			for ($i = 0; $i < $num_rows;) {
				   //echo $array[$i]['pelajar']."<br>";
				   addFilter($i+1, 'or', 1, 'equal-to', $array[$i]['pelajar']);
				   $i ++;
			}

		}
	}

Re: What is the best way to filter data in hooks

Posted: 2021-01-28 09:15
by onoehring
Hi,

I am not sure what you are asking for / want to accomplish.
I am replying to hint to to a bug that still exists in 5.94 in the datatypes.php and which caused ma a lot of headache working with a custom filter. Please see here for a description and a quick fix from Ahmed ( viewtopic.php?f=11&t=4143 ).

Olaf

Re: What is the best way to filter data in hooks

Posted: 2021-01-28 19:49
by pbottcher
Hi,

you could try to shorten the code a little bit, but other than that it is just fine.

Code: Select all

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

		if ($memberInfo['group']=="Penyelia"){
			$pelajar = sql("SELECT pelajar FROM Seliaan WHERE penyelia=(select id FROM ".$memberInfo['group']." WHERE milik = '".$memberInfo['username']."')", $eo);
			$i=1;
			while ($row = db_fetch_assoc($pelajar)) {
				   addFilter($i, 'or', 1, 'equal-to', $row['pelajar']);
				   $i++;
			}
		}
	}
Code is not tested and may have syntax errors