Page 1 of 1

how to filter valuelists(solved)

PostPosted: Mon Oct 08, 2012 2:44 pm
by zmmaj
well this is situation...

I have in table several Admins... but every of them can add own customer in table client
I was use command beforeSave() to save on one field of table client Admin UserName...

now I need to make valuelist for Admin, but with only that client name who have in filed saved Admin UserName ...

I was use next:
Code: Select all
function valuelist__Majstor(){
    static $majstor = -1;
    if ( !is_array($majstor) ){
        $majstor = array();
        $rest = mysql_query("select ID, ImePrezime from majstori", df_db());
        if ( !$rest ) throw new Exception(mysql_error(df_db()));
        while ($rowt = mysql_fetch_row($rest) ) $majstor[$rowt[0]] = $rowt[1];
    }
    return $majstor;
}

But in this case Admin can see every ImePrezime from every Admin... That is NOT goal...

I need something like...
Code: Select all
function valuelist__Majstor(){
    static $majstor = -1;
    if ( !is_array($majstor) ){
        $majstor = array();
        $rest = mysql_query("select ID, ImePrezime from majstori", df_db());
       $AdminName =mysql_query("select ID,AdminName from majstori", df_db());
        if ( !$rest ) throw new Exception(mysql_error(df_db()));
        while ($rowt = mysql_fetch_row($rest) and $AdminName = $user->val('UserName') ) $majstor[$rowt[0]] = $rowt[1];
    }
    return $majstor;
}

But this wont work.... :(
help?

Re: how to filter valuelists

PostPosted: Wed Oct 10, 2012 12:07 am
by silma
You said you have one field "AdminUsername" in the client table, so why not include it in the request ?

Code: Select all
   
function valuelist__Client() {
   $auth =& Dataface_AuthenticationTool::getInstance();
   $user =& $auth->getLoggedInUser();

   $username = $user->val("Username");

   $out = array();

   $sql = "select ClientID, ClientName from clienttable where AdminUsername='".$username."' order by ClientName";
   $res = mysql_query($sql, df_db());
   while ($row = mysql_fetch_assoc($res) ) $out[$row['ClientID']] = $row['ClientName'];
      
   return $out;
}
   
   

Re: how to filter valuelists

PostPosted: Wed Oct 10, 2012 5:14 am
by zmmaj
Thank you man..,. that is that what I need :)))