I wonder whether someone may be able to help me please. Firstly, my apologies as to some this be a very basic question, I’m very new to working with XML so please bear with me.
I’m using this section of code to successfully load marker data from a MySQL database, placing them on a Google map.
downloadUrl("loadallmyfinds.php", function(data) {
var xml = parseXml(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("findosgb36lat"));
var lng = parseFloat(markers[i].getAttribute("findosgb36lon"));
var point = new google.maps.LatLng(lat,lng);
var locationname = markers[i].getAttribute("locationname");
var finddescription = markers[i].getAttribute("finddescription");
var html = "<b>" + 'Description: ' + "</b>" + finddescription;
var findcategory = markers[i].getAttribute("findcategory");
// create the marker
var marker = createMarker(point,html,locationname,finddescription,findcategory);
}
XML Output
<markers>
<marker userid="27" findid="1" locationname="Test Location 1" findosgb36lat="53.0000" findosgb36lon="-1.00000" osgridref="" dateoftrip="21/06/2012" findcategory="Artefact" finddescription="A rare Roman vase."/>
</markers>
The problem I have, is that in it’s current state all records are being retrieved irrespective of the user, but I need to make this user specific, to be more precise, if the userid element value matches the variable I have on my form which is $idnum.
I thought that I may be able to do this via the PHP query that is being loaded in the above i.e. loadallmyfinds using a GET clause, but sadly this doesn’t work.
I’ve done some research into this and I believe, from my limited knowledge, that I may be able to this via XML, but I’m really not sure how to implement it.
i just wondered whether someone could possibly look at this please and offer some guidance on how I may go about it so the records are filtered.
Many thanks and kind regards
You have the user id in the as
$idnum. So, please change your ajax request from this:downloadUrl("loadallmyfinds.php", function(data) {to this:
downloadUrl("loadallmyfinds.php?id=<?php echo $idnum?>", function(data) {and in the
loadallmyfinds.phpfile:OLD COMMENT
I guess you can store the userid in your session (
$_SESSION['uid']=$userId;)…and in your
loadallmyfinds.phpfile, read this session variable and return only that user related content.