Variables

A place for users and developers of the Xataface to discuss and receive support.

Variables

Postby Philipp Wenzel » Sun Aug 12, 2012 3:52 am

Hi Steve,
i really like our work. It make my work so much easier. Thanks again.

Lately i have a little problem:
I try to make dynamic valuelist entries, like u explain in the Using Value-list tutorial. Further more i'd like to manipulate the query with a simple WHERE adding in the code. This is the Basic, like the one in the tutorial and it works fine.

Code: Select all
[gesetz]
__sql__ = "SELECT gesetz_id, gesetz_name FROM gesetz"


Now with the WHERE:

Code: Select all
[gesetz]
__sql__ = "SELECT gesetz_id, gesetz_name FROM gesetz WHERE nation_id = '$nation_id'"

as result i have an empty valuelist.

im not sure if the variable is right. how are the db filds are stored in a variable? Or is it possible to do a WHERE querry in the valuelist.ini?

Greetz,
Philipp
Philipp Wenzel
 
Posts: 15
Joined: Sat May 05, 2012 7:10 am

Re: Variables

Postby shannah » Mon Aug 13, 2012 9:26 pm

Valuelists don't accept variables, since they are meant to be loaded once per request. If you really need to change the valuelist depending on context, then you could implement the valuelist with a delegate class method (e.g. valuelist__xxx()) try to make it so that it only makes the db request once per http request for performance reasons.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Variables

Postby Philipp Wenzel » Tue Aug 14, 2012 1:23 am

Alright! Thanks a lot.
I will try the delegate class thingy :)
Philipp Wenzel
 
Posts: 15
Joined: Sat May 05, 2012 7:10 am

Re: Variables

Postby Philipp Wenzel » Tue Aug 14, 2012 10:51 am

Hi,
i tried to use the valuelist__xxx() function an after a research in the forum this, what i came up with:

Code: Select all
   function valuelist__gesetz(){   
      $res = mysql_query("select gesetz_id, nation_id, gesetz_name from gesetz WHERE nation_id = '$record->val('nation_id')'");
      $out = array();
       while ( $row = mysql_fetch_assoc($res) ) $out[$row['gesetz_id']] = $row['gesetz_name'];
      return $out;
   }


this happens in a related table (mastertable is nation, from the master i need the selected nation_id information).
but it wont work. im guessing it is something about the variable '$record->val('nation_id')'. But i can't figure it out. My programming skills are really not that good. :/

How can i access the selected data from the mastertable to perform this query?
Greetings,
Philipp
Philipp Wenzel
 
Posts: 15
Joined: Sat May 05, 2012 7:10 am

Re: Variables

Postby shannah » Mon Aug 20, 2012 10:56 am

It sounds like you may be using a valuelist for something that it can't do very will. My guess is that you have a select list in an edit form and you want it to show different options depending on which record is being edited.

If this is the case, then you will need to do some Javascript to dynamically build the select list depending on the values in other fields. I have developed a depselect widget that requires Xataface 2.0 which handles this sort of thing automatically:
http://xataface.com/dox/modules/depselect/latest/

You can take a look at the source of this for some hints. There have also been a number of other discussions in the forum on how to build similar things.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 19 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved