[mapserver-users] Another mailing list for MapServer?

Peter Rose peter_rose at hotmail.com
Fri May 8 12:02:07 EDT 2009


Hi,

A PHP script accesses MySQL to retrieve dynamic information, and uses the
PHP MapScript APA to render a map. It displays a map of the UK with shires,
rivers etc. from the content of several shapefiles. Each point (POI) of
interest is renders directly from the geographical coordinates stored in the
MySQL Database. 
The user is able to search the database directly on the website by sending a
Select statement which in turn generates the pages. 

You can try the website yourself by going to  -
http://mapserver.cch.kcl.ac.uk/pase/pasemap2.php
If you search for the Latin Name = Edward, you should get 8 results. 
This site is still very much a work in progress and things change may change
at any time!

What I want to do is to display the dots on the map in various colours and
sizes according to the fiscal values in the database. Fx. So that all values
over 3 are large and red while everything under 3 is small and green. 
The fiscal values are kept in a Float field in the MySQL database. 
The important thing here is that the data is kept in my MySQL database, not
in a shapefile, as I have to be able to change it from time to time.  
I know that if these values had been kept in the shapefile I could just
insert the Expression ([fiscal] < 3) in the mapfile as my example
illustrate.
However, this doesn’t work with MySQL. 

My connection to the database takes place in the PHP script like you would
normally do it (see bottom of page). As for the Mapfile, only the section I
have already shown deals with the points of interest. The rest has to do
with the shapefiles, scale, legend etc. and are therefore not relevant for
this question. 

Since the layer is rendered dynamically from a database it does not need a
DATA statement. It can still display the points as you can see from the
website. 
As for the expressions not working, what I mean is that only the first class
is shown (here it's the "Large fiscal" class with a red dot). But the
filtering hasn't taken place so all query results are shown not just the <1
and they are all red. Mapserver therefore seems to ignore the expression all
together. It also works without the expression.  It makes no difference
whether or not the expression is there. 

Thank you everyone for helping me with this one. I hope a solution to my
question will be helpful to other MapServer user. 
Hope you all have a good weekend.
Best regards,
Peter


//------------------------------------------
// GetStoreTable - returns array containing store table

function GetStoreTable($Name, $SearchField) {

     // Retrieve store table from MySQL database

     mysql_connect("localhost", "mysql", "password")
              or die("Could not connect to MySQL server!");

     mysql_select_db("mydatabase")
              or die("Could not select database");


// The basic SELECT statement
$select = ' SELECT * ';
$from   = ' FROM Property';
$where  = ' WHERE 1=1';

// Retrieve Search text
$Name = $_GET['Name'];
$SearchField = $_GET['SearchField'];

//Select table field
if (($SearchField == 'latinName') AND ($Name != '')) { // SearchField is set
to latinName and there is some search text
  $where .= " AND Tenant.latinName LIKE '$Name'";
} 

if (($SearchField == 'normalisedName') AND ($Name != '')) { // SearchField
is set to normalisedName and there is some search text
  $where .= " AND Tenant.normalisedName LIKE '$Name'";
}  

if (($SearchField == 'latinDescriptor') AND ($Name != '')) { // SearchField
is set to latinDescriptor and there is some search text
  $where .= " AND Tenant.latinDescriptor LIKE '$Name'";
}  

if (($SearchField == 'englishDescriptor') AND ($Name != '')) { //
SearchField is set to englishDescriptor and there is some search text
  $where .= " AND Tenant.englishDescriptor LIKE '$Name'";
}  

// Join Tenant and Property tables
	$from   = $from.' RIGHT JOIN Tenant USING (propertyKey)';

// Limit Query to 2000
	$where = $where." LIMIT 2000";

   $result = mysql_query($select . $from . $where);

if (mysql_num_rows($result) < 1){
	exit ('Could not locate any places with these search criteria. Please Click
' . ' "Back" and try again. ');
    }

     // Save each row of result in an array

     $i = 0;
     while ( $row = mysql_fetch_array($result,MYSQL_NUM) ) {
        $qresult[$i] = $row;
        $i++;
     }

     // return array of results

     return $qresult;

} // end GetStoreTable




-- 
View this message in context: http://n2.nabble.com/Another-mailing-list-for-MapServer--tp2844517p2846149.html
Sent from the Mapserver - User mailing list archive at Nabble.com.



More information about the mapserver-users mailing list