[Mapserver-users] Re: On-the-fly generated picklists in query-forms

Puneet Kishor pkishor at geoanalytics.com
Mon Oct 27 12:56:08 EST 2003


Roman,

For clarity my response is right here at the top -- the rest of the email thread is at the end. You want to know how to --

> 2. You query those tables to get some values with which you 
> generate a form
> on the
> fly.

with php/mapscript. The above has nothing to do with mapscript... Again, if I have understood you correclty, this is a pure and simple php (or any scripting language) task, and one of the commonest in any dynamic website. The approach is thus (I am giving a Perl example because that is what I use on a regular basis, but you would do pretty much the same with PHP) --

# 1. connect to the database and get a db handle. I use DBI
my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","", { PrintError => 1, RaiseError => 1 });

# 2. create the sql statement  
my $sql = "SELECT state_code, state_name FROM states";

# create a statement handle
my $sth = $dbh->prepare(qq{$sql});

# execute the darn thing
$sth->execute;

# get a reference to an array of hashes. Each hash is a row, 
# and the array is the result set of all the rows returned
my $results = $sth->fetchall_arrayref({});

# 3. I use a templating system so I can pass the ref above
# directly to the template. This is how I do it -- first 
# populate the template variable 
$template->param('results' => $results);

# then send the obligatory Content-Type and print the template
print "Content-Type: text/html\n\n", $template->output;

####### end ##########

Now in my html template I have code like so --


<select name="state_code" size="1">
<option value="">Choose state...</option>
<tmpl_loop results>
<option value="<tmpl_var state_code>"><tmpl_var state_name></option>
</tmpl_loop>
</select>


Done.


Now, forget about the template stuff for now (actually, don't forget it, but lets talk about it later). You will do the same with PHP (the steps below correspond with the numbers above).

1. Connect to the database and get a handle
2. Prepare and execute the query and get the results
3. Output the results

Now, templates -- I highly recommend the use of templates. In my view, it is just plain good application design. Perl has many templating systems -- I use HTML::Template. I have put a basic but complete working example of an H::T based Mapserver applicatoni.

I am not sure what exists on the PHP side, but Google will help you in that (there used to be something called Smarty -- dunno what its development state is).


> -----Original Message-----
> From: Roman Meier [mailto:mapserver at gismap.ch] 
> Sent: Monday, October 27, 2003 11:31 AM
> To: Mapserver-Userlist; Puneet Kishor
> Subject: AW: [Mapserver-users] Re: On-the-fly generated 
> picklists in query-forms
> 
> 
> Hi
> 
> It seems, that everything is perfectly clear to you. The 
> problem for me is
> point no 2. How can I query the tables and get the values to 
> build the form
> using php/mapscript? Did you do something like this before?
> 
> Thanks for help and patience, Roman
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: mapserver-users-admin at lists.gis.umn.edu
> [mailto:mapserver-users-admin at lists.gis.umn.edu]Im Auftrag von
> pkishor_98
> Gesendet: Sonntag, 26. Oktober 2003 14:41
> An: mapserver-users at lists.gis.umn.edu
> Betreff: [Mapserver-users] Re: On-the-fly generated picklists in
> query-forms
> 
> 
> --- In mapserver-users at yahoogroups.com, "Roman Meier" <mapserver at g...>
> wrote:
> > Hi again
> >
> > Sorry, let me try again and give you some more informations 
> on what I'm
> > planning to do...
> >
> > The user of my webgis will be able to add values to the 
> database (postgis)
> > and to query the data using a form. That's why I dont want 
> to use a common
> > picklist in the form because I dont know what values have 
> been entered by
> > the user. The picklist must be generated on-the-fly.
> >
> > I hope, things are more clear now...
> 
> 
> unfortunately they are not. Because your problem seems to be 
> exactly the
> same as
> what you stated earlier. Let me try to break it up into its 
> components --
> 
> 1. User enters info in a database table (or tables).
> 2. You query those tables to get some values with which you 
> generate a form
> on the
> fly.
> 3. User picks values from that form.
> 4. Query the database again to get the details on the record queried.
> 
> So where is the problem? Everything is being generated on the fly...
> 
> 
> 
> 
> >
> > -----Ursprüngliche Nachricht-----
> > Von: mapserver-users-admin at l...
> > [mailto:mapserver-users-admin at l...]Im Auftrag von
> > pkishor_98
> > Gesendet: Samstag, 25. Oktober 2003 22:33
> > An: mapserver-users at l...
> > Betreff: [Mapserver-users] Re: On-the-fly generated picklists in
> > query-forms
> >
> >
> > --- In mapserver-users at yahoogroups.com, "Roman Meier" 
> <mapserver at g...>
> > wrote:
> > > Hi list
> > >
> > > A bit off topic maybe...
> >
> > really ;-)
> >
> > >
> > > I would like to implement an unconventional picklist in 
> my queries.
> Using
> > a
> > > form, the user should have the possibility to select the 
> searchstring
> out
> > of
> > > a picklist. The picklist is generated on-the-fly(!). The function
> searches
> > > the table (postgis, mysql or dbf) for all items, that 
> have been entered
> > > before...
> > >
> > > - Did somebody do something like this before?
> > > - How can I implement this using php/mapscript and postgis?
> > > - Any ideas?
> > >
> >
> > given that you are asking this, I am going to assume there 
> is something
> > specific here
> > that is out of the ordinary... I mean, this is one of the commonest
> devices
> > one sees on
> > the web, so why...?
> >
> > Anyway -- assuming you want to populate a form using values from a
> table --
> >
> > 1. query the table for values and text, and create a form
> >
> > select values, text from table where whatever
> >
> > <option value=$value>$text</option>
> >
> > and then use the $value to query the database for the results.
> >
> > If you want something that focuses on the items as you type 
> characters,
> you
> > can fill a
> > javascript array with the $text values, and then use 
> onkeypress to trap
> the
> > characters
> > as they are typed, search through the array, calculate the 
> selectedindex
> and
> > focus on
> > the fly. Is that what you asking?
> >
> > If it is something else you are asking, my apologies -- I didn't
> understand
> > the
> > question.
> >
> >
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at l...
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> >
> >
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at l...
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 
> 




More information about the mapserver-users mailing list