I have the following code stored in a 'genxml.php' that generates markers on google maps. The file is called from another file 'mobileInterface.php'. If I add another marker location in the database everything is working fine on a computer browser, the only problem that I have is when loading from a mobile browser, markers do no update instantly, I have to exit the browser and load it again to update. Else I have to load the 'genxml.php' directly from the URL, sort of downloading the contents and then load 'mobileInterface.php' again.
I have tried not caching the page contents but still I have this problem. Any ideas please?
//genxml.php
$query = "SELECT * ,DATE_FORMAT( ts, '%d-%m-%Y : %H.%i.%s' ) as tz FROM dataentry WHERE caseStatus = 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = #mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'id="' . parseToXML($row['id']) . '" ';
echo 'riskCategory="' . parseToXML($row['riskCategory']) . '" ';
echo 'EventAccidentSubject="' . parseToXML($row['EventAccidentSubject']) . '" ';
echo 'description="' . parseToXML($row['description']) . '" ';
echo 'peopleInvolved="' . parseToXML($row['peopleInvolved']) . '" ';
echo 'hazards="' . parseToXML($row['hazards']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'caseStatus="' . parseToXML($row['caseStatus']) . '" ';
echo 'ts="' . $row['tz'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
//mobileInterface.php
var mobileInterfaceServer = "http://10.0.0.21/genxml.php";
downloadUrl(mobileInterfaceServer, function(markers) {//replace markers with data
var xml = markers.responseXML;//replace markers with data
var markers = xml.documentElement.getElementsByTagName("marker");
selectBox = document.getElementById('destination');
for (var i = 0; i < markers.length; i++) {
var riskCategory = markers[i].getAttribute("riskCategory");
var EventAccidentSubject = markers[i].getAttribute("EventAccidentSubject");
var address = markers[i].getAttribute("address");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
html = "<b>" + EventAccidentSubject + "</b> <br/>" + address;
displayLocation(markers[i]);
//displayLocation(point);
addOption(selectBox, markers[i].getAttribute("EventAccidentSubject"), point);
bindInfoWindow(marker, map, infoWindow, html);
}
Add a timestamp to the request for data from the server as described in this answer
Related
i have a stored routine called collection_get_category_suggestions which has the following sql
select *
from album
where category=InCategory;
This should return a list of multiple records based on a category the user chooses. When run in sql tab the result of the routine returns multiple values however when executed in the routine tab and JavaScript it will only return the first record. Here is my JavaScript function which handles sql.
function getCategorySuggestions(catid)
{
var categoryid = catid;
console.log(categoryid);
selectedcategory = categoryid;
$("#suggestionsTab").empty();
var url = "categories_xml.php?category=" + selectedcategory;
$.ajax({
type: "GET",
url: url,
dataType: "xml",
success: function(xml){
var album_title = $(xml).find('album_title').text();
console.log(album_title);
var artist = $(xml).find('artist').text();
var year = $(xml).find('year').text();
var imageurl = $(xml).find('imageurl').text();
var categoryinfo = "<h3>" + album_title + "</h3><p>" + artist + " (" + year + ")</p>";
//categoryinfo += "<img src='" + imageurl + "' alt='" + album_title + " Album Cover' height='200' width='200' />";
console.log(categoryinfo);
$('#suggestionsTab').append(categoryinfo);
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
}
the console.log returns one record. Why is this? Thanks very much for any help
EDIT:
php script
<?php
// Include utility files
require_once 'include/config.php';
// Load the database handler
require_once BUSINESS_DIR . 'database_handler.php';
// Load Business Tier
require_once BUSINESS_DIR . 'collection.php';
header("Content-type: text/xml");
$response='<?xml version = "1.0" ?><albums>';
if (isset($_GET['category']))
{
$obj = Collection::GetCategorySuggestions($_GET['category']);
$album_title=$obj['album_title'];
$artist=$obj['artist'];
$category=$obj['category'];
$year=$obj['release_date'];
$imageurl="./images/" . $obj['image'];
$response .= '<album><album_title>' . htmlentities($album_title, ENT_QUOTES) . '</album_title>';
$response .= '<artist>' . htmlentities($artist, ENT_QUOTES) . '</artist>';
$response .= '<category>' . htmlentities($category, ENT_QUOTES) . '</category>';
$response .= '<year>' . $year . '</year>';
$response .= '<imageurl>' . htmlentities($imageurl, ENT_QUOTES) . '</imageurl></album>';
}
$response .= '</albums>';
echo $response;
?>
i should add that the collection.php function is
public static function GetCategorySuggestions($category)
{
// Build SQL query
$sql = 'CALL collection_get_category_suggestions (:category)';
// Build the parameters array
$params = array (':category' => $category);
// Execute the query and return the results
return DatabaseHandler::GetRow($sql, $params);
}
foreach loop
foreach($albumsarray as $album)
{
$album_id=$album['album_id'];
$album_title=$album['album_title'];
$artist=$album['artist'];
$response .= '<album><album_id>' . $album_id . '</album_id><album_title>' . htmlentities($album_title, ENT_QUOTES) . '</album_title><artist>' . htmlentities($artist, ENT_QUOTES) . '</artist></album>';
}
I have a php query like so:
<?php
$query = "SELECT * FROM " . $usertable . " ORDER BY fname;";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo '<option value="' . $row['pkid'] . '">' . $row['fname'] . ' ' . $row['lname'] . '</option>';
}
?>
Within this same .php file I have some javascript. All I would like to do is return $row['fname'] as a a javascript variable.
Is this possible?
If you want to output the PHP variable in a JavaScript variable you could do something like this -
echo '<script>var name+' . $row['pkid'] . ' = ' .$row['fname'] . ';</script>';
This would give you a uniquely named variable for each row.
To generate the stockroom drop down list
function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) {
//connect to database
base_connectDatabase();
echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">";
if (isset($Stockrm) && ($Stockrm != "")) {
$stockrmname = einv_getStockrmDetail($Stockrm);
echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>";
} else {
$Stockrm = 0;
}
$getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name");
while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) {
if (base_num_rows($getStockrmSQL)!= 0) {
echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>";
}
}
echo "</select>";
echo "<script src=\"../terms_base/js/jquery.multiple.select.js\"> </script>";
//Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll
if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3
$SDDArrays = explode(";", $dropdown);
$countTrap0 = count($SDDArrays);
$drop = "$('#stockrm').multipleSelect(\"setSelects\", [";
$counting = 1;
foreach ($SDDArrays as &$value) {
if ($countTrap0 != $counting) {
$drop .= "'". $value . "',";
} else {
$drop .= "'". $value . "'";
}
$counting++;
}
$drop .= "]);\n";
} elseif (isset($dropdown)) { //dropdown=
$drop = "$('#stockrm').multipleSelect(\"uncheckAll\")";
} else { //
$drop = "$('#stockrm').multipleSelect(\"checkAll\")";
}
echo "<script>\n";
echo "$(function() {\n";
echo "".$drop."";
echo "});\n";
echo "$(\"#stockrm\").multipleSelect({ onClose: function() {
document.getElementById('search').click();
}});\n";
echo "$(\"#stockrm\").multipleSelect();\n";
echo "</script>";
//close the database
base_closeDatabase();
}
//This function is use to add new stock room
//code = stock room code
//name = stock room name
//desc = stock room description
//remark = stock room remark
//cat = stock room category
add stockroom function
function einv_addStockrm($code,$name,$desc,$remark,$cat)
{
//connect to database
base_connectDatabase();
$User = base_getUserDetail($_SESSION['uID']);
base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat)
VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')");
base_addTransactionLog('Manage Stock Room', 'Add',
"
Stock Room Code = " . $code . " ||
Stock Room Name = " . $name . " ||
Stock Room Description = " . $desc . " ||
Stock Room Remark = " . $remark . " ||
Stock Room Category = " . $cat . "
");
//go to stock room page
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../einventory/stockrm_list.php";';
echo '</script>';
//close the database
base_closeDatabase();
}
Edit stockroom
function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat)
{
//connect to database
base_connectDatabase();
$User = base_getUserDetail($_SESSION['uID']);
$Stockroom = einv_getStockrmDetail($srid);
base_executeSQL("UPDATE einv_stockroom
SET einv_stockrm_code='" . $code . "',
einv_stockrm_name='" . $name . "',
einv_stockrm_desc='" . $desc . "',
einv_stockrm_remark='" . $remark . "',
einv_stockrm_cat = '" . $cat . "'
WHERE einv_stockrm_id=" . $srid . "");
base_addTransactionLog('Manage Stock Room', 'Edit',
"
Stock Room Code = " . $code . " ||
Stock Room Name = " . $name . " ||
Stock Room Description = " . $desc . " ||
Stock Room Remark = " . $remark . " ||
Stock Room Category = " . $cat . "
");
//go to stock room page
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";';
echo '</script>';
//close the database
base_closeDatabase();
}
File name: add_Stockroom.php and edit_stockroom.php
I have a dropdown list named Stockroom where it displays an array of values.
Example:
Stockroom
[A]
[B]
[C]
When user clicks on [A], it will display relevant data fields that [A] possess (appears below stockroom ddl).
And as user clicks on [B], there is an onchange function that will then show [B] data fields (fields in A is deleted and replaced with B).
I am able to add the initial values however, as i want to edit and change the stockroom from [A] to [B] which will result in a whole new data to be stored, i am unable to do so.
Any ideas?
I believe i have to amend my edit stockroom function where i require a set of coding such as
If the array is selected, i have to delete existing data and add new data in accordance to the selected ID.
Right now I have a grid and each grid part/bit contains an image, the name of the item and different buttons that can delete the item from the mysql database and update the price. What I want to do know is that when a user say clicks on the image a window would pop up where extra information would be displayed. However it is not a pop up in a usual sense that it would create another window but rather a pop up within the current window/tab. E.g. When you press on a photo in Facebook it creates almost like a popup on which you can comment or change to the next photo. Does anyone have any idea on how to do this or at least what is the whole thing/process called?
Sorry if I can't give a proper name but I don't know it myself :/
Here is the code to what I have now. I would prefer an actual code solution but if you can lead me to where I should look for it I would also be happy. I tried looking online however everything I get is window pop ups.
<div class="boxes">
<?php
$ID = $_SESSION['SESS_MEMBER_ID'];
$con = mysql_connect("", "", "");
if (!$con){
die("Cannot connect: " . mysql_error());
}
mysql_select_db("test", $con);
$sql = "SELECT * FROM items WHERE member_id = $ID";
$myData = mysql_query($sql, $con);
$dir = 'Images';
$symbol = '\\';
$end = 'r.jpg';
$currency = '£';
while($record = mysql_fetch_array($myData)) {
$real_name = str_replace('_', ' ', $record['Name']);
$result = $dir . $symbol . $record['Name'] . $end;
$value = $currency . $record['price_now'];
$link = $record['url'];
echo "<div class = frame>";
echo "<div class = bit-3>";
echo "<div class = box>" . "<img src=" . $result . " alt=some_text>";
echo "<br />";
echo "<br />";
echo $real_name;
echo "<br />";
echo "<br />";
echo "Price now: " . $value;
echo "<form action = member-profile-page.php method = post>";
echo "Desired price: ";
echo "<td>" . "<input type = text name = desired_price value = " . $record['desired_price'] . " </td>";
echo "<td>" . "<input type = hidden name = hidden value = " . $record['Id'] . " </td>";
echo " ";
echo "<td>" . "<input type = submit name = update value = Update" . " </td>";
echo "<br />";
echo "<br />";
echo "<td>" . "<input type = submit name = delete value = Delete" . " </td>";
echo "<br />";
echo "<br />";
echo "<td>" . "<input type = submit name = buy value = Buy" . " </td>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
}
if (isset($_POST['buy'])){
$query = "select url from items where Id = '$_POST[hidden]'";
if ($result = mysql_query($query)) {
$row = mysql_fetch_assoc($result);
$code = $row['url'];
echo "$code";
header("Location: $code");
}
};
if (isset($_POST['update'])){
$UpdateQuery = "UPDATE items SET desired_price = '$_POST[desired_price]' WHERE Id = '$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};
if (isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM items WHERE Id = '$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};
mysql_close($con);
?>
</div>
Sounds like you're looking for an overlay:
http://jquerytools.org/demos/overlay/index.html
or a modal:
https://jqueryui.com/dialog/
These are by no means the only examples; there are hundreds of such solutions. These will get you started, though. Good luck!
What you think about is just a layer in the current browser viewport, having some controls to let the user handle it like a "desktop window".
There are quite a lot of JS frameworks offering handy solutions for this, i.e. jQuery UI. Within there, look for "dialog"
I've added an image URL to an entry in the mySQL database, and I want it do be displayed in the information window on my sidebar.
Here's what the part I'm fiddling around with:
downloadUrl("genxml.php", function(data) {
var xml = data.responseXML;
var locations = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < locations.length; i++) {
var name = locations[i].getAttribute("name");
var address = locations[i].getAttribute("address");
var type = locations[i].getAttribute("type");
var price = locations[i].getAttribute("price");
var img = locations[i].getAttribute("img");
var point = new google.maps.LatLng(
parseFloat(locations[i].getAttribute("lat")),
parseFloat(locations[i].getAttribute("lng")));
var html = "<div class=loc-img><img src=" + img + "/></div><div class=loc-name>" + name + "</div> <br/>" + address + "<br/>" + "<div class=loc-type>" + type + "</div><div id=loc-price>Price Rating:" + price + "</div>";
The bit at the bottom looks right to me, so I can't work out what's wrong.
The image is saved on the server, and the URL has been added to the img field of the entry, and there are no spelling errors. When the page loads, and the info window loads, this shows in the Inspector.
<img src="null/">
Here are the details of the column from phpMyAdmin, whcih I think could be causing the problem. varchar(120) latin1_swedish_ci, Null is set to no. I assumed that because it was a URL, varchar would be the appropriate choice.
Any thoughts?
EDIT: I am also having a similar issues with another field. I think it might be related. There's a 'price' field, set to int(5), and is simply a rating of 1 to 5. However, when the info window displays, it just says 'null'
I've actually managed to work out the problem.
Rather simple, yet easily overlooked!
When adding new fields to each item, you need to remember to register them in the XML converter that pulls the information from the database, and then converts it to a Maps-readable format (XML).
In my case, I had to go into genxml.php (as directed by the Maps documentation), and make it look like this:
while ($row = #mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo 'price="' . $row['price'] . '" ';
echo 'img="' . $row['img'] . '" ';
echo '/>';
}
Hope that helps someone else!