Jump to content

garry27

Members
  • Posts

    161
  • Joined

  • Last visited

    Never

Everything posted by garry27

  1. i now get 'object undefined on  line 24' but no 'markers undefined' in my javascript: [code]function init() { // JavaScript coding from Purvis et al (2006: p.22, p.29)   if ( GBrowserIsCompatible() ) {                          map = new GMap2(document.getElementById("mapviewer"));     map.addControl( new GSmallMapControl () );     //map.addControl( new GMap2TypeControl () );          //undefined?     //map.addControl( new GLatLng ( centerLatitude, centreLongitude ), startZoom ); //location = GLatLng(centerLatitude, centerLongitude); map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);     for ( id in markers ) {   addMarker( markers[id].latitude, markers[id].longitude, markers[id].name );  // line 24     }   } }[/code] ???
  2. i tried the code you posted and i'm getting: [quote]Notice  Undefined variable: key in /map_data.php on line 15[/quote] refering to the foreach loop.
  3. i've got a web page which calls on two scripts to deliver it a google map containing markers as defined by coordinates on  my database. the first script, map_data.php, pulls out these co-ordinates and formats it in a javascript data structure. it then outputs the js back to the browser. the second is a js script which contains instructions to pass on to google in order for it to pass the map to my browser. this includes a reference to the markers variable containing the data required for the markers (longitude and longitude, as well as some optional values). the problem is that my web app isn't working as described. currently it pulls up the map but my markers are absent. my debugger tells me that 'markers is undefined' on line 23 and there's no js when i right mouse click soure on the page (although i'm not sure if there's meant to be). the code for both scripts is shown below. can someone look at it and tell me what's wrong with it. thanks [b]map_data.php[/b] [code]<?php            function getPubMarkers() {     require_once('common.php');     db_connect();     $sql = mysql_query ( " select Latitude, Longitude, pubName, pubStreetNo, pubStreet, pubCity, pubCounty,                         pubPostcode, pubPhone from Pubs " ) or die( 'Invalid query: ' . mysql_error() );         while( $elements = mysql_fetch_array($sql) ) { $br = '<br>';          $markers[] =      '{'                          ." 'latitude' : " .$elements[0] .',' ." 'longitude' : " .$elements[1] .','                         ." 'name' : '" .$elements[2] ."' ,"                     //    ."'address': '" .$elements[3] .$br .$elements[4] .$br .$elements[5]                      //                    .$br .$elements[6] .$br .$elements[7] ."' ,"                     //    ."'phone': '" .$elements[8] ."'"       .'},';     }     //convert array into a single string variable     $markers  = implode( ' ', $markers );     //remove the end comma in the string     $markers = substr_replace($markers,"",-1);         $jscript = 'var markers =' .'[' .$markers .'];';     return $jscript; } ?>[/code] [b]map_js.js[/b] [code]var map; var centerLatitude = 54.524842;        // global var var centerLongitude = 1.556604;        // global var var startZoom = 3; //function addMarker() function init() { // JavaScript coding from Purvis et al (2006: p.22, p.29)   if ( GBrowserIsCompatible() ) {                          map = new GMap2(document.getElementById("mapviewer"));     map.addControl( new GSmallMapControl () );     //map.addControl( new GMap2TypeControl () );          //undefined?     //map.addControl( new GLatLng ( centerLatitude, centreLongitude ), startZoom ); //location = GLatLng(centerLatitude, centerLongitude); map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);     for ( id in markers ) {                                                                                          //line 24   addMarker( markers[id].latitude, markers[id].longitude, markers[id].name );  [id].address, markers[id].phone     }   } } //opens map when browser window loads up window.onload = init; window.onunload = GUnload;[/code]
  4. that's great! thanks for all the advice, fellas.
  5. yes, the numbers match up but i'm also trying to fetch several rows. is there a built in function or some other way i can do this?  :)
  6. i still get the same error. here's the code from the start of the function: [code]function a(){   $sql = mysql_query ( "select Longitude from Pubs" );   $longitude = mysql_fetch_array($sql);   if (!$sql){   die('Invalid query: ' . mysql_error());   }   $sql = mysql_query ( "select Latitude from Pubs" );   $latitude = mysql_fetch_array($sql);   if (!$sql){   die('Invalid query: ' . mysql_error());   }       $result = count($longitude); $location = array(); for($i=0; $i<$result; $i++) { $location[] = "{$longitude[$i]},{$latitude[$i]}"; }[/code] did you mean to leave the index value blank for location inside the loop? i get the same error messages both ways anyway  :-\ cheers for the help
  7. i'm tring to create a new array called $location which will consist of the values of two other arrays $longitude and $latitude (both of which have an equal number of values) joined together in asingle string (plus the comma). am i doing this right because i keep getting errors saying "undefined offset...in line 31" [code] $result = count($longitude); for ( $i = 0; $i <$result; $i++ ) {     $location[$i] = array ( $longitude[$i].','.$latitude[$i] );      //line 31 }[/code]
  8. thanks for the help guys. i'm now using google maps api to build a prototype web app and its pretty comprehensive so i won't need answers to my questions . for the time being i'm using an alternative site (http://gaze.mysociety.org) for the search function on my prototype app which you can query for geocode by placename. they says that you must use "HTTP GETs" and make the request directly via url. would using  HttpMessage::getBody work for recieving messages in csv format? i'm not too sure how i should make a request. i was thinking of writing a php function which would take the location from an input box and proccess the request and results from the response locally. can this work during runtime without affecting the browser?
  9. If anyone has any experience or knowledge of commercial GIS mapping solutions for websites and how they integrate with PHP, please can you answer the questions below. I would be ever grateful and you would be helping me with my final year undergraduate project. [b]I've read that some providers communicate in XML, do you know of any examples on the web (access to code xml document trees etc.)?[/b] [b]How do GIS software providers provide the map to the client and in what format is it? [/b] [b]What information does the client need to send in order for the provider to process a request for a map?[/b] [b]What information does the provider need to send back to the client in order to enable them to plot objects on the map they have recieved? [/b] [b]Will the client need specialised software in order to plot real co-ordinates on the map (for example if they wanted to plot the location of a pub using real geographical co-ordinates)?[/b] [b]If I were to use the PHP's longitude and latitude co-orrdinate functions to plot the objects on the map at the client end, would I be able to do this with a street level map? If it can, then how? [/b]
  10. i've sorted it now, thanks. it was a lot simpler problem than i thought. [code]sort ($chkbox_arr);   $result = count($chkbox_arr);   echo $result;   for ( $i = 0; $i <$result; $i++ )   $chkbox_arr[$i]="AND $chkbox_arr[$i]='y'";[/code]
  11. i'm trying to do something like this but using for so it keeps track of the index: [code]foreach ($chkbox_arr as &$value) $value = "AND $chkbox_arr 'y'"; [/code] if i use the code above all i get is AND Array 'y' for each value that is returned. instead of the actual value contained in the array it just says Array. i has a similar problem with this when i tried to create $ckbox_arr array using a a foreach loop.  ???
  12. ok. i'm trying to adjust each value in the $chkbox_arr array so that it adds " AND *followed by the value* ='y' " this array im trying to store in $sql_ arr currently each value in  $chkbox_arr is a string word which relate to a column on a mysql table i will then use the implode function to add the new values together in a single string so i can use in a where clasuse in mysql. the problem now is that the only result i'm getting is: AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' ..regardless of what's in the $chkbox_arr array
  13. i have this code: [code]for ( $i = 0; $i <10; $i++ ) $chkbox_arr[$i];      for ( $ii = 0; $ii <10; $ii++ )       $sql_arr[$ii] = ' AND '.$chkbox_arr[$i]."='y' "; [/code] what I'm trying to do is create a new array which adds ' AND '.$chkbox_arr[$i]."='y' "; for each value in $chkbox_array. but all i get is: AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' pleasecan someone show me how to fix this. thanks in advance
  14. hi, i've been on this for hours now and wondering if anyone can help me. i'm trying to loop through the array below in order to remove any elements which don't  return a 'true' value when i $post them. i do this using unset. if i echo out an element whilst in the loop, it echos out the right data. howver when i call the array after the end of the loop- the element which i unset magically reapeears. hoorah!  ::) [code]$chkbox_arr = array ( 'dj', 'liveMusic', 'nsArea','food','skySport', 'cocktails'             ,'pool', 'garden', 'lateLice', 'kidsZone' );       for ( $i = 0; $i <10; $i++ )   {     $element = $chkbox_arr[$i];     $chkbox_value = $_POST[$element];     if ($chkbox_value != 'true')       unset($element);   }     for ( $i = 0; $i <11; $i++ )     echo "$chkbox_arr[$i]  ";[/code]
  15. cos php is a server-side language, you won't be able to execute any php from the browser without querying the server first (unlike javascript). you can put your validate data code on the testport.php after the db connects. something like this for example: if ($email == '')   echo 'you have forgotten to type an email address on your form'; you can also store it on the same script if you wanted and make the script self-execute after the user clicks submit. this is a better option as the script will contain the form again, if the user forgets to fill something out.
  16. what makes you think that what i want to do requires a loop?  ::)
  17. i meant to say insert, not update. with the current code i can only insert one record for any given pub in the Event table. if you read from the end of the if statements block below *****validate user input********* to the end of the script, you should see what i am trying to do with it. i can't see anything wrong with the code or why it's behaving the way it is, which is why i've included the entire function for adding puv events. thanks in advance
  18. hi, i've written a script that updates data into a Events table in mysql via a form which has info regarding events (date, heading and body) that i plan to update onto a calendar later on. the current problem i have is that using the current code, it will only update a single record for any given pub into the Events table. here's the relivant mysql tables: [code]TABLE Pub( userEmail              VARCHAR(25) NOT NULL, pubName                CHAR(20) NOT NULL, pubStreetNo            SMALLINT NOT NULL, pubStreet              VARCHAR(20) NOT NULL, pubCity                VARCHAR(20) NOT NULL, pubCounty              CHAR(20) NOT NULL, pubPostcode          CHAR(8 ) NOT NULL, pubPhone                BIGINT NOT NULL, PRIMARY KEY(pubName, pubPostcode, userEmail)); TABLE Event( pubName                    CHAR(20) NOT NULL, pubPostcode              CHAR(8 ) NOT NULL, eventDate                  DATE NOT NULL, eventHeading              VARCHAR(25) NOT NULL, eventBody                  CHAR(20) NOT NULL, PRIMARY KEY(pubName, pubPostcode));[/code] and the php function that validate and adds the event: [code]   function add_event() {   // connect to db   db_connect();   $day = stripslashes ( trim ( $_POST['day'] ) );   $month = stripslashes (trim ( $_POST['month'] ) );   $year = stripslashes ( trim ( $_POST['year'] ) );   $heading = stripslashes (trim ( $_POST['heading'] ) );   $body = stripslashes ( trim ( $_POST['body'] ) ); /********** validate user input ********************************************************/      // format date for mysql   $date =($year."-".$month."-".$day);   if ( !checkdate((int)$day, (int)$month, (int)$year) )   {   echo 'Please type the date in the correct format (DD/MM/YYYY)';   }   // notice! - if heading missing   if ($heading == '')     echo 'please enter a name for your event';   // notice! if main text body missing   if ($body == '')     echo 'please enter a few details for your event';   // assign variable to logged on useremail   $email =  $_SESSION['valid_user'];     // get pubName of 'valid user'   $sql = mysql_query ( "select pubName from Pub where userEmail='$email'" );   $row = mysql_fetch_row($sql);   $pubname = $row[0];   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }     // get pubPostcode of 'valid user'   $sql = mysql_query ( "select pubPostcode from Pub where userEmail='$email'" );   $row = mysql_fetch_row($sql);   $pubpostcode = $row[0];   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }       //check if calendar slot is taken   $sql = mysql_query("select * from Event where eventDate='$date' and pubName='$pubname' and pubPostcode='$pubpostcode'");   $num_rows = mysql_num_rows($sql);   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }   if ($num_rows >0 )   {     echo 'You already have an event for that day!'; return;   }   /************ add date/event if ok  ***************************************/     //specify pub in pub table   $sql = mysql_query("select * from Pub   where pubName= '$pubname'   and pubPostcode='$pubpostcode'");   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }   else   {   // add event   $sq2 = mysql_query("insert into Event                       set eventHeading = '$heading',       eventDate = '$date',   eventBody = '$body',   pubName= '$pubname',   pubPostcode='$pubpostcode'");     } } [/code] i know a lot of the data in the Event table is redundant and could to with being broken down but besides that, i can't see any logical reason why i can't update more than one record per pub. please someone help me with this garry
  19. all positive feedback is very welcome. it doesn't have to be a solution.  :-\
  20. take a look at http://www.planetsourcecode.com/  8)
  21. hi, i've written a script that updates data into a Events table in mysql via a form which has info regarding events (date, heading and body) that i plan to update onto a calendar later on. the current problem i have is that using the current code, it will only update a single record for any given pub into the Events table. here's the relivant mysql tables: TABLE Pub( userEmail              VARCHAR(25) NOT NULL, pubName                CHAR(20) NOT NULL, pubStreetNo            SMALLINT NOT NULL, pubStreet              VARCHAR(20) NOT NULL, pubCity                VARCHAR(20) NOT NULL, pubCounty              CHAR(20) NOT NULL, pubPostcode         CHAR(8 ) NOT NULL, pubPhone                BIGINT NOT NULL, PRIMARY KEY(pubName, pubPostcode, userEmail)); TABLE Event( pubName                    CHAR(20) NOT NULL, pubPostcode           CHAR(8 ) NOT NULL, eventDate                  DATE NOT NULL, eventHeading              VARCHAR(25) NOT NULL, eventBody                  CHAR(20) NOT NULL, PRIMARY KEY(pubName, pubPostcode)); and the php function that validate and adds the event: [code]  function add_event() {   // connect to db   db_connect();   $day = stripslashes ( trim ( $_POST['day'] ) );   $month = stripslashes (trim ( $_POST['month'] ) );   $year = stripslashes ( trim ( $_POST['year'] ) );   $heading = stripslashes (trim ( $_POST['heading'] ) );   $body = stripslashes ( trim ( $_POST['body'] ) ); /********** validate user input ********************************************************/      // format date for mysql   $date =($year."-".$month."-".$day);   if ( !checkdate((int)$day, (int)$month, (int)$year) )   {   echo 'Please type the date in the correct format (DD/MM/YYYY)';   }   // notice! - if heading missing   if ($heading == '')     echo 'please enter a name for your event';   // notice! if main text body missing   if ($body == '')     echo 'please enter a few details for your event';   // assign variable to logged on useremail   $email =  $_SESSION['valid_user'];     // get pubName of 'valid user'   $sql = mysql_query ( "select pubName from Pub where userEmail='$email'" );   $row = mysql_fetch_row($sql);   $pubname = $row[0];   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }     // get pubPostcode of 'valid user'   $sql = mysql_query ( "select pubPostcode from Pub where userEmail='$email'" );   $row = mysql_fetch_row($sql);   $pubpostcode = $row[0];   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }       //check if calendar slot is taken   $sql = mysql_query("select * from Event where eventDate='$date' and pubName='$pubname' and pubPostcode='$pubpostcode'");   $num_rows = mysql_num_rows($sql);   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }   if ($num_rows >0 )   {     echo 'You already have an event for that day!'; return;   }   /************ add date/event if ok  ***************************************/     //specify pub in pub table   $sql = mysql_query("select * from Pub   where pubName= '$pubname'   and pubPostcode='$pubpostcode'");   if (!$sql)   {     die('Invalid query: ' . mysql_error());     echo 'Could not add event at this time - please try later.'; return;   }   else   {   // add event   $sq2 = mysql_query("insert into Event                       set eventHeading = '$heading',       eventDate = '$date',   eventBody = '$body',   pubName= '$pubname',   pubPostcode='$pubpostcode'");     } } [/code] i know a lot of the data in the Event table is redundant and could to with being broken down but besides that, i can't see any logical reason why i can't update more than one record per pub. please can somone take a look cheers garry
  22. i have a self executable login script with a form that validates login credentials when you click the submit button. what could i do to get it to redirect the user to another page as soon as it validates the user and carries the session variable on to the new script?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.