
php_novice2007
Members-
Posts
124 -
Joined
-
Last visited
Never
Everything posted by php_novice2007
-
Hi, I've got two timestamp strings, str1 and str2, in the format "yyyy-mm-dd hh:mm:ss". I want to do str1 - str2 and have the answer as in integer in seconds. Is there a function out there that I can use or do I have to manually tokenise both strings and then do subtractions... cos I'm thinking its gonna get confusing if the day is different.. Thanks!
-
it is just remembering and reading the oldest file (even if the file has changed). The page is accessed when the user clicks on a link.
-
Hi, I'm a bit confused.. what do I have to do? This is my code originally: <?php //start the session session_start(); //check to make sure the session variable is registered if(session_is_registered('userid')){ if ($_SESSION['group']=="admin") { $doc = new DomDocument('1.0'); $node = $doc->createElement("positions"); $parnode = $doc->appendChild($node); $all = 0; $num = 0; if (isset($_POST['a']) || isset($_POST['b'])) { if(isset($_POST['a']) && isset($_POST['unitNum']) && !isset($_POST['b'])){ $all = 1; $unitNUM = $_POST['unitNum']; $unitNum = "u" . str_pad($unitNUM, 4, "0", STR_PAD_LEFT); // pad the number with 0 to make it a 4 digit number require("databaseInfo.php"); $dbtable = $unitNum; $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); //The whole contents of $dbtable from the red1 database is now contained in $result. $query="SELECT * FROM ".$dbtable; $result=mysql_query($query, $link) or die("Unable to load selected table"); //find out how many rows there are in the database $num=mysql_num_rows($result) or die("There are no results"); //close link mysql_close($link) or die("Unable to close database"); } else { if(!isset($_POST['a']) && isset($_POST['b']) && isset($_POST['sday']) && isset($_POST['smonth']) && isset($_POST['syear']) && isset($_POST['eday']) && isset($_POST['emonth']) && isset($_POST['eyear']) && isset($_POST['unitNum'])){ $num = 0; $start = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']." 00:00:00"; $end = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']." 23:59:59"; $unitNUM = $_POST['unitNum']; $unitNum = "u" . str_pad($unitNUM, 4, "0", STR_PAD_LEFT); // pad the number with 0 to make it a 4 digit number require("databaseInfo.php"); $dbtable = $unitNum; $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); //The whole contents of $dbtable from the red1 database is now contained in $result. $query="SELECT * FROM `$dbtable` WHERE fixdatetime >= '$start' AND fixdatetime <= '$end'"; $result=mysql_query($query, $link) or die("Unable to load selected table"); //find out how many rows there are in the database $num=mysql_num_rows($result); //close link mysql_close($link) or die("Unable to close database"); } } if ($num > 0) { $myFile = $unitNum."AdminData".".txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, "$num \n"); $i=0; //to iterate through each row while ($i < $num) { $lat=mysql_result($result,$i,"lat"); $long=mysql_result($result,$i,"lng"); $timestamp = mysql_result($result,$i,"fixdatetime"); $node = $doc->createElement("position"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("timestamp", $timestamp); $newnode->setAttribute("latitude", $lat); $newnode->setAttribute("longitude", $long); $stringData =$timestamp.",".$lat.",".$long."\n"; fwrite($fh, $stringData); $i++; } fclose($fh); //generate xml $doc->formatOutput = true; // set the formatOutput attribute of domDocument to true // save XML as string or file //$test1 = $doc->saveXML(); // put string in test1 $xmlName = $unitNum.".xml"; $doc->save($xmlName); // save as file ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Query Results</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA_ZKXKLNCYSzHFMNyG-Bj2xQXwYfUv9Msb5tvjKK5I8eE-jDdexQRB0gnc-9SRTy-FhW0Wii5KFTosg" type="text/javascript"></script> <script src="http://www.acme.com/javascript/OverlayMessage.js" type="text/javascript"></script> <script src="http://www.acme.com/javascript/Clusterer2.jsm" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function createMarker(point,iCon) { var marker = new GMarker(point,iCon); return marker; } var om; var toggleState=1; var markerArray = []; var pointsArray = []; var clusterer; var map; function loadMap() { if (GBrowserIsCompatible()) { //display the loading message om = new OverlayMessage(document.getElementById('map')); om.Set('<b>Map is loading...</b>'); var icon = new GIcon(); icon.iconSize = new GSize(12,20); icon.iconAnchor = new GPoint(6,20); iconblue = new GIcon(icon, "http://labs.google.com/ridefinder/images/mm_20_blue.png"); //create the map map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(0,0),0); //create bounds object to set zoom level to fit all datapoints var bounds = new GLatLngBounds(); // create the clusterer clusterer = new Clusterer(map); // set the clusterer parameters if you dont like the defaults //clusterer.maxVisibleMarkers = 50; //clusterer.gridSize = 5; clusterer.minMarkersPerClusterer = 3; GDownloadUrl("<? echo $xmlName;?>", function(data) { var xml = GXml.parse(data); var positions = xml.documentElement.getElementsByTagName("position"); for (var i = 0; i < positions.length; i++) { var point = new GLatLng(parseFloat(positions[i].getAttribute("latitude")), parseFloat(positions[i].getAttribute("longitude"))); pointsArray[i] = point; var marker = createMarker(point,iconblue); clusterer.AddMarker(marker); markerArray[i] = marker; //map.addOverlay(marker); bounds.extend(point); } map.setZoom(map.getBoundsZoomLevel(bounds)); map.setCenter(bounds.getCenter()); map.addOverlay(new GPolyline(pointsArray,"#0000FF",2)); }); } else { // display a warning if the browser was not compatible alert("Sorry, the Google Maps API is not compatible with this browser"); } } //remove the loading message when the page has finished loading function clearmessage() { om.Clear(); } function toggleMarkers() { //clusterer = new Clusterer(map); if (toggleState == 1) { map.getPane(G_MAP_MARKER_PANE).style.visibility="hidden"; toggleState = 0; } else { map.getPane(G_MAP_MARKER_PANE).style.visibility="visible"; toggleState = 1; } } //]]> </script> </head> <body bgcolor="#CCFFCC" onload="loadMap(); clearmessage();" onunload="GUnload()"> <? if ($all == 1) { echo "<center><h1>Sea Grass Tracker Data for Unit $unitNUM </h1></center><br>"; } else { echo "<h1><center>Results from $start to $end for unit $unitNUM</center></h1><br>"; } ?> <center><div id="map" style="width: 650px; height: 550px"></div></center> <input id="markerToggler" type="button" onclick="toggleMarkers();" value="Toggle Markers"> <br><a href=<? echo $myFile;?>>Raw Unit Data</a> <br><a href=displayAdmin.php>Go Back</a> </body></html> <? } else { echo "There are no results. <br><br><a href=displayAdmin.php>Go Back</a>"; } } else { echo "This page require input from somewhere else."; echo "<br><a href=secureMenuAdmin.php>Back to Menu</a>"; } } else { // someone has logged on but is not admin echo "You do not have permission to access this page.<br><br><a href=secureMenu.php>Back to Menu</a>"; } } else { echo "You are not logged in, please go <a href=loginForm.html>here</a> to login"; } ?> Thanks p.s. Sorry I'm still waiting for things to be set up so I can't put a link to the page and show what I'm talking about...
-
Hi, I'm writing a page where each time it is loaded, PHP script is used to generate an xml file as well as a text file. Then javascript is used to read the xml file and generate some plots on the page. Each time the page is loaded the xml file should be changing, however the Javascript seems to be remembering the very first file generated and plot the same thing even though the file has changed. I checked the file manually in the directory and indeed the xml file is different yet the javascript is still printing old stuff. I tried putting just a <a href..> link to the file and it is displaying the old file no the newest one.. So far I found that if I close the browser and open it again then it works. How do I make javascript read the "latest" file... Thanks~!
-
Hi, I want to program a link where instead of a text file opening when the user clicks on it I want one of those pop up windows which allow them to download the file.. I can't seem to find how to do it anywhere Any help would be great! Thanks~!
-
Hi, I'm writing a page which allows someone to reset their password. I have 2 text fields for them to type in the new password 2 times. I want to have a check box above them so that when the user clicks on the check box, these two fields appear, otherwise they should be hidden. How can I go about doing this? I can't seem to find any tutorial on how this can be done either.. thanks
-
I just read the condition of use and it says I'm allowed to download a copy for my own use. So I'm guessing its alright if I'm working on a local machine?
-
I want to go to this site http://www.weatherzone.com.au/station.jsp?lt=site&lc=61366&list=ob and extract the time, wind dir, wind spd, wind gust, and tmp values from the table. I want to store the data in an xml file or mysql table.. Thanks
-
Hi, I'm thinking of learning to write my own web fetching script in PHP.. does anyone know any good tutorial that teaches how to do this? I tried google, but all the links that I clicked on seems to go to no where... :S Thanks!
-
I know how to do the string[0] bit in PHP, its just $str[0]. $str[1:-1] unfortunately doesn't work..
-
hmm I tried your code but nothing got printed :S I only want to remove the first ".", if there are subsequent "." I want to keep them..
-
Hi, i've got a string which begins with a ".", how can I get rid of it? e.g. $str = ".hello", I want $str = "hello" thanks!
-
Hi, This is the page that I'm writing.. http://www.ug.it.usyd.edu.au/~chui6762/googleMap/map2.html basically while the map is loading I should get a message that says "Map is loading" in a blue box which disappear when the map is fully loaded.. currently I'm not seeing the blue box at all. If I comment out the line om.Clear(); then I'll get the blue box on top of the map forever.. So is it actually working but just disappearing so quickly that I don't catch it? my map isn't loaded instantly though... thanks for any help
-
Hi, I'm trying to use PHP to create an XML file from a MySQL database.. I'm following a tutorial from http://imagine-it.org/google/tutorial_phpsqlajax.htm and it says to call domxml_new_doc() to check if my server's PHP has dom_xml functionality on. When I tried it, it says the function is undefined.. the tutorial doesn't tell me how to fix it. Can anyone help? thanks~!
-
Hi, I'm trying to use php code to read some longitudes and latitudes and then plot them on google map. Heres my code: <?php // establish link $username="root"; $password="abcd"; $database="red1"; $dbtable = $u0100; $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); //The whole contents of $dbtable from the red1 database is now contained in $result. $query="SELECT * FROM ".$dbtable; $result=mysql_query($query, $link) or die("Unable to load selected table"); //find out how many rows there are in the database $num=mysql_num_rows($result) or die("There are no results"); //close link mysql_close($link) or die("Unable to close database"); $lat = array(); $long = array(); $i = 0; while ($i<$num) { $lat[$i]=mysql_result($result,$i,"lat"); $long[$i]=mysql_result($result,$i,"lng"); $i++; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Track Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA_ZKXKLNCYSzHFMNyG-Bj2xQXwYfUv9Mi5KFTosg" type="text/javascript"></script> <script type="text/javascript"> function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(<?php echo $lat[0]; ?>, <?php echo $long[0]; ?>), 13); var points = []; <?php for ($i=1;$i<count($lat);$i++) { echo "points.push(new GLatLng($lat[$i],$long[$i]));"; } ?> map.addOverlay(new GPolyline(points)); } } </script> </head> <body onload="load()" onunload="GUnload()" text="#E76300" link="#E76300"> <div id="map" style="width: 500px; height: 300px"></div> <font style="color:#E76300; font-family: courier;"> <br /> </body> </html> My problem is when I try to load the page I get this pop up which says: "A script on this page is causing mozilla to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?" If I click "ok", it keeps popping up again, if I click "cancel", I get a map being loaded, but no track on it.. Is there something wrong with my script? There are currently 453 points that I want to plot (this number is growing though...) Another question: How can I define the size of the map generated? I read the API and it says that I can add in a width and height, so I just added in two numbers like var map = new GMap2(document.getElementById("map"),20,50); this doesnt seem to work... I don't think I'm using it correctly Thanks!!
-
Sweet, thanks~! I'm curious... How come the other way didn't work?
-
Hi, I'm trying to use the array_unique function and its not giving me some of my values... So for example, $input = array("4", "4", "3", "4", "3", "5","7","7"); $indiGroup = array_unique($input); for($j=0; $j < count($indiGroup); $j++) { print "<option value=$indiGroup[$j]>$indiGroup[$j]</option>"; } When I put this code in my page, my drop down lists has "4", and then a gap, and then "3", and then a gap.. It seems to be missing every second one. ???
-
bump.. Anybody? I still can't get it working.. And now I'm writing a page which toggle some values in the database and now if I click refresh it gets toggled again, ie back to original.. I've tried unsetting the $_POST variable, but that doesn't seem to work.. Please help..
-
Thanks, I fixed it by getting rid of the single quotes around $unitNum
-
It doesn't seem to work.. Notice: Undefined index: $unitNum in I:\webpages\editViewUser1.php on line 49 Warning: Invalid argument supplied for foreach() in I:\webpages\editViewUser1.php on line 49 The code: foreach($unit_id as $unitNum) { foreach($_POST['$unitNum'] as $k => $v) { echo "$k was checked"; } } Whats $v?
-
Hi, This probably is really simple, but I'm kind of stuck... how do i use php to check if check boxes are clicked? So far I have <form name="myform" action="editViewUser1.php" method="POST"> Please select the unit number to toggle its public viewability: <br> <?php for($j=0; $j < count($unit_id); $j++) { print "<input type=checkbox name=$unit_id[$j]> $unit_id[$j]<br>"; } ?> <input type="Submit" name="a" value="Toggle Viewability"> </form> and for my processing part... foreach($unit_id as $unitNum) { if (isset($_POST['$unitNum'])) { echo "$unitNum is checked<br>"; } else { echo "$unitNum is not checked<br>"; } } right now my code says that none of my boxes are checked, even if i did check some... How shoud I do it? Thanks~!
-
Hi, I just tried adding your two lines into my code.. <?php if (isset($_POST['unitNum'])) { $unitNum = $_POST['unitNum']; } // establish link $username="root"; $password="abcd"; $database="red1"; $dbtable = "commands"; $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); $query="DELETE FROM `$dbtable` WHERE `$dbtable`.`unit_id` = $unitNum LIMIT 1;"; $result=mysql_query($query, $link) or die("Unable to delete"); //close link mysql_close($link) or die("Unable to close database"); //Redirect Here header( 'Location: comands.php'); ob_end_flush(); //I use this to prevent header/output issues ?> I'm getting these messages when I try to go to deleteCommand.php.. Warning: Cannot modify header information - headers already sent by (output started at I:\webpages\deleteCommand.php:2) in I:\webpages\deleteCommand.php on line 24 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in I:\webpages\deleteCommand.php on line 25 Is the code meant to automatically go back to commands.php after the entry is deleted?
-
hmm true.. what about if I'm trying to add records to my database? Then if I click refresh would it tries to add it again?
-
hmm where exactly would i put the header line..? my code currently : <html> <body> <?php if (isset($_POST['unitNum'])) { $unitNum = $_POST['unitNum']; } // establish link $username="root"; $password="abcd"; $database="red1"; $dbtable = "commands"; $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database"); //select database @mysql_select_db($database) or die("Unable to select database"); $query="DELETE FROM `$dbtable` WHERE `$dbtable`.`unit_id` = $unitNum LIMIT 1;"; $result=mysql_query($query, $link) or die("Unable to delete"); //close link mysql_close($link) or die("Unable to close database"); ?> Command for unit <?php echo $unitNum; ?> is deleted.<br><br> <a href="commands.php">Go back to commands page</a> </body> </html>