Jump to content

nita

Members
  • Posts

    86
  • Joined

  • Last visited

Everything posted by nita

  1. Have basic article directory and i'm busy with pagination. And i want to have it shortlinked. Structure of the link looks like this: Without pagination <a href='moving-articles/category/$sublink/'>$sublink</a> rewrite rule in .htaccess look like this RewriteRule moving-articles/(.*)/(.*)/$ /moving-articles.php?$1=$2 That works perfectly fine. So the problem i have here, one i try to add pagination. Link structure is like this for example: <a href='moving-articles/category/$sublink/page/2/'>2</a> rewrite rule in .htaccess: RewriteRule moving-articles/(.*)/(.*)/(.*)/(.*)/$ /moving-articles.php?$1=$2&$3=$4 And piece of php code responsible for calling variables: if(isset($_GET['category']) && isset($_GET['page'])) { $sublink=$_GET['category']; $page=$_GET['page']; ..... } What do i do wrong here? Thanks for your help in advance!
  2. improved version: <? include "connectdb.php"; $driver = 5; $datestamp = '2013/05/07'; $result2 = mysql_query("SELECT * FROM drivers WHERE id='$driver' LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $garage_lon=$row2['lon']; $garage_lat=$row2['lat']; } $result = mysql_query("SELECT * FROM quotedb WHERE moveday='$datestamp' AND driver='$driver' AND cleared='Not Cleared' AND status='Done' ORDER BY moveday, timeday") or die(mysql_error()); function calculate_distance($lon1, $lat1, $lon2, $lat2) { return (3958 * 3.1415926 * sqrt(($lat2 - $lat1) * ($lat2 - $lat1) + cos($lat2 / 57.29578) * cos($lat1 / 57.29578) * ($lon2 - $lon1) * ($lon2 - $lon1)) / 180);} $previous_lon = $garage_lon; $previous_lat = $garage_lat; $distance = 0; // accumulate the distance while($row = mysql_fetch_assoc( $result )) { $lon1 = $row['lon1']; $lat1 = $row['lat1']; $lon2 = $row['lon2']; $lat2 = $row['lat2']; if ( $previous_lon && $previous_lat ) { // calculate the distance from the Garage to the first point of the first row $distance += calculate_distance($lon1, $lat1, $previous_lon, $previous_lat); } // calculate the distance for each row (segment) in the route $distance += calculate_distance($lon1, $lat1, $lon2, $lat2); $previous_lon = $lon2; $previous_lat = $lat2; } // calculate the distance from the second point of the last row to the Garage $distance += calculate_distance($garage_lon, $garage_lat, $lon2, $lat2); $distance = round($distance,0); echo "$distance<br> "; ?>
  3. Ok. I worked it out. All calculations are done as i wish. My code below: <? include "connectdb.php"; $driver = 5; $datestamp = '2013/05/07'; $result2 = mysql_query("SELECT * FROM drivers WHERE id='$driver' LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $lon=$row2['lon']; $lat=$row2['lat']; } $result = mysql_query("SELECT * FROM quotedb WHERE moveday='$datestamp' AND driver='$driver' AND cleared='Not Cleared' AND status='Done' ORDER BY moveday, timeday") or die(mysql_error()); $distance = 0; // accumulate the distance $first_pass = true; // flag to detect the first row inside the loop while($row = mysql_fetch_assoc( $result )) { $lon2a=$lon2; $lat2a=$lat2; $lon1=$row['lon1']; $lat1=$row['lat1']; $lon2=$row['lon2']; $lat2=$row['lat2']; // calculate the distance from the Garage to the first point of the first row if($first_pass){ $distance += (3958*3.1415926*sqrt(($lat-$lat1)*($lat-$lat1) + cos($lat/57.29578)*cos($lat1/57.29578)*($lon-$lon1)*($lon-$lon1))/180); $first_pass = false; } // calculate the distance for each row (segment) in the route $distance += (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); if ( $lon2a == "" or $lat2a =="" ) { } else { // calculate the distance from the second point of the first row to the first point of the next row $distance += (3958*3.1415926*sqrt(($lat2a-$lat1)*($lat2a-$lat1) + cos($lat2a/57.29578)*cos($lat1/57.29578)*($lon2a-$lon1)*($lon2a-$lon1))/180); } } // calculate the distance from the second point of the last row to the Garage $distance += (3958*3.1415926*sqrt(($lat2-$lat)*($lat2-$lat) + cos($lat2/57.29578)*cos($lat/57.29578)*($lon2-$lon)*($lon2-$lon))/180); echo "$distance<br> "; ?> Don't get me wrong, but i think it can be done more proffesional way.. that is what i try to achive .. and still have a lot to learn - i realize that. Do you guys have some suggestion to improve this piece of code ..(will aplay Haversine method for calculations). THX
  4. guess you right, working on it, manual (on paper thats easy) - missing logic in my code ...
  5. There is proggres. Code calculates distance beetween garage and starting point of 1st location. Then calculates well distances between starting points and finishing points of locations. Also calculate well distance between dinishing point of the last location and garage. What im missing is: distances between finishig pont of 1st location and starting point of 2nd location and so on ... (Garage + D1) + (D1 + D2) + (D2 + E1) + (E1 + E2) + E2 + Garage)
  6. how do i aplay: $distance += calc_distance($lat1,$lon1,$lat2,$lon2); should i use function: function calc_distance ($lat1, $lon1, $lat2, $lon2) { return (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); } but then what about $distance += calc_distance($lat2,$lon2,$lat,$lon); the variables are different ????
  7. i will aplay other calculation method for sure. My problem here at the moment is to que up calculations. Thank for a tip.
  8. Came up with following code: <? include "connectdb.php"; $driver = 5; $datestamp = '2013/05/07'; $result2 = mysql_query("SELECT * FROM drivers WHERE id='$driver' LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $lon=$row2['lon']; $lat=$row2['lat']; } ?> <? $distance = 0; // accumulate the distance $result = mysql_query("SELECT * FROM quotedb WHERE moveday='$datestamp' AND driver='$driver' AND cleared='Not Cleared' AND status='Done' ORDER BY moveday, timeday") or die(mysql_error()); while($row = mysql_fetch_assoc( $result )) { $first_pass = true; // flag to detect the first row inside the loop $lon1=$row['lon1']; $lat1=$row['lat1']; $lon2=$row['lon2']; $lat2=$row['lat2']; echo "$lon, $lat<br>$lon1, $lat1, $lon2, $lat2<br>"; // calculate the distance from the Garage to the first point of the first row if($first_pass){ $distance += (3958*3.1415926*sqrt(($lat-$lat1)*($lat-$lat1) + cos($lat/57.29578)*cos($lat1/57.29578)*($lon-$lon1)*($lon-$lon1))/180); $first_pass = false; } // calculate the distance for each row (segment) in the route $distance += (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); } // calculate the distance from the second point of the last row to the Garage $distance += (3958*3.1415926*sqrt(($lat2-$lat)*($lat2-$lat) + cos($lat2/57.29578)*cos($lat/57.29578)*($lon2-$lon)*($lon2-$lon))/180); echo "$distance"; ?>
  9. I would like to calculate the total distance of driving beetween multiple locations (loop), including the distance (starting point (garage) - first location sarting point) and (last location finishig point - finishing point (garage)). Example: (Garage + D1) + (D1 + D2) + (D2 + E1) + (E1 + E2) + E2 + Garage) I'm having a problem with the correct looping. Here's my simplified code: <? $driver = 5; $result2 = mysql_query("SELECT * FROM test WHERE id='$driver' LIMIT 1") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $lon=$row2['lon']; $lat=$row2['lat']; echo "$lon, $lat"; } $result = mysql_query("SELECT * FROM test1 WHERE driver='$driver'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $lon1=$row['lon1']; $lat1=$row['lat1']; $lon2=$row['lon2']; $lat2=$row['lat2']; ////////// distance between driver address and starting address $distancecalc = (3958*3.1415926*sqrt(($lat-$lat1)*($lat-$lat1) + cos($lat/57.29578)*cos($lat1/57.29578)*($lon-$lon1)*($lon-$lon1))/180); ////////// distance between statring address and finishing address - multiple adsresses $distancecalc1 = $distancecalc1 + (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); ////////// distance between finishing address and driver address $distancecalc2 = (3958*3.1415926*sqrt(($lat2-$lat)*($lat2-$lat) + cos($lat2/57.29578)*cos($lat/57.29578)*($lon2-$lon)*($lon2-$lon))/180); $distancetotal = $distancecalc + $distancecalc1 +$distancecalc2; echo "$distancecalc<br> $distancecalc1<br> $distancecalc2<br>"; } echo "$distancetotal"; ?> I'm aware that code posted above doesnt't do what it meant to .. i just want to keep it clear.. there is some things i tried but no correct resoults. I would appreciate some help on this one. Thank you very much.
  10. function validateForm(){ var inputs = document.getElementsByTagName('input'); var noneZeroFound = false; for(var i=0;i< inputs.length;i++){ var input = inputs[i]; if(input.value != '0'){ noneZeroFound = true; break; } } if(!noneZeroFound ){ alert('MUST ENTER VALUE...'); return false; } return true; } <form name='packaging' action="packaging.php" method='post' onSubmit="return validateForm()"> Found the solution on another forum.
  11. Hi Everyone. I'm working on a basic ordering form. What i'm trying to achive is to get javascript to return alert when all the inputs fields are with values 0. At least 1 of the inputs has to be filled in with value more then 0 in order to proceed with a ordering form. I have to mention that products list / input fields are generated dynamicly so their number might vary. Basic code: <form name='packaging' action="packaging.php" method='post'> <? $result = mysql_query("SELECT * FROM packaging_items") or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo " <input type='text' style='width:20px' name='$row[prodno]' id='$row[prodno]' maxlength='4' value="0" onblur="if (this.value == '') {this.value = '0';}" onfocus="if (this.value == '0') {this.value = '';}" onkeypress='validate(event)' > "; } ?> </form> Any suggetions .. i really have no clue where to start ... Thank you in advance
  12. Certainly will take your advice in mind, will look into JOIN mysql, could you give me some link with basic example that i can look into and learn, that is what i need ! Thank you
  13. got it fixed ... $result1=mysql_query("SELECT ".$data1." as data1 FROM packaging WHERE orderno='$orderno' LIMIT 1") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { $data = $row1['data1']; if ( $data == '' ) {} else { echo" <tr><td>$name</td><td>$data</td><td>£$price</td><tr>"; } }
  14. for example when i hardcode the query, results are ok and that is what i want to achive here $result1=mysql_query("SELECT pack01 FROM packaging WHERE orderno='$orderno' LIMIT 1") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { $pack01 = $row1['pack01']; echo "$pack01"; }
  15. Hi everone. Having a problem with getting the values from a database. What im trying to do is: I use variable 'varname' from packaging_items table (values are coressponding to the names of columns in packaging table ... pack01, pack02 .. and so on). But in query result1 instead of getting the value of (pack01, pack02 ..) i get the names of columns (pack01, pack02 ..) Here is my short code: (ofcourse there is more to it, but this bit is most important) $result = mysql_query("SELECT * FROM packaging_items") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $data1 = $row['varname']; $name = $row['name']; $price = $row['price']; [/background][/size][/font][/color] [color=#464646][font='Helvetica Neue', Helvetica, Arial, sans-serif][size=3][background=rgb(244, 244, 244)]$result1=mysql_query("SELECT `$data1` FROM packaging WHERE orderno='$orderno' LIMIT 1") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { if ( $data1 == '' ) {} else { echo" <tr><td>$name</td><td>$data1</td><td>£$price</td><tr>"; } } } Im stuck here, tried some other options .. and only get worst.. What do i wrong .. if someone can help will be nice. Thank you in advance!
  16. There was a problem in calling a distance() function. Function is defined as lat, lon, lat, lon, but i called it as lon, lat, lon, lat. Being blind. SOLVED.
  17. Hi I have a problem with implementing variables into a function that calculate distance between 2 latitudes, longitudes. One of them is constant, and the second one being passed from the form. Here is the code: $lon1 = $_POST['lon1']; $lat1 = $_POST['lat1']; $lon2 = '-0.30020239'; $lat2 = '51.58734910'; function distance($lat11, $lon11, $lat22, $lon22) { $theta = $lon11 - $lon22; $dist = sin(deg2rad($lat11)) * sin(deg2rad($lat22)) + cos(deg2rad($lat11)) * cos(deg2rad($lat22)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; return $miles; } [/background][/size][/font][/color] [color=#464646][font='Helvetica Neue', Helvetica, Arial, sans-serif][size=3][background=rgb(244, 244, 244)]echo " $lon1, $lat1<br> $lon2, $lat2<br>"; ////////// return good calculation echo distance(52.611644, -0.26304, 51.58734910, -0.30020239) . " miles<br>"; [/background][/size][/font][/color] [color=#464646][font='Helvetica Neue', Helvetica, Arial, sans-serif][size=3][background=rgb(244, 244, 244)]////////// my way - return wrong calculation echo distance("$lon1", "$lat1", 51.58734910, -0.30020239) . " miles<br>"; As long as i have lat, lon values hardcoded is fine, but idea is to have this calculation done from variables. Both will vary .... tried different configurations ... i'm losing it ... How should I code it ?? Thanks for your help in advance!
  18. having some time helps !!! Solved Postcode:<input id="postcode" name="postcode" type="text" size="10" onchange="usePointFromPostcode(document.getElementById('postcode').value)" /><br> Postcode 1:<input id="postcode1" name="postcode1"type="text" size="10" onchange="usePointFromPostcode1(document.getElementById('postcode1').value)"/><br>
  19. Tried with that: <form name="latlon" action="test2a.php" method='post' onchange="usePointFromPostcode(document.getElementById('postcode').value); usePointFromPostcode1(document.getElementById('postcode1').value); "> dosn't work as it should.
  20. Maybe i'm not clear enough here ... all i want is to type in 2 postodes in the form so i can get their lat / lon and pass these values to another page, (hidden inputs to be used) im not so much into javascript but maybe there is some other way ... problem is in the form (getting lat / lon works fine) any suggestions ... Thank You
  21. Hi there ! What i'm traying to do is to get latitude and longitude form imputed postcodes. Which works fine as long as i stick to only one input (first or second seperate). I can't get it to work once i try with both of them. i'm using onchange event .. Please ake a look at the form: <form name="latlon" action="test2a.php" method='post' onchange="return usePointFromPostcode(document.getElementById('postcode').value) && usePointFromPostcode1(document.getElementById('postcode1').value) "> <input id="postcode" type="text" size="10" /><br> <input id="postcode1" type="text" size="10"/><br> Latitude:<input name="lat" type="text" id="lat" size="10"/><br /> Longitude:<input name="lon" type="text" id="lon" size="10"/><br><br> Latitude:<input name="lat1" type="text" id="lat1" size="10"/><br /> Longitude:<input name="lon1" type="text" id="lon1" size="10"/> <input type="submit" value="Get Lat / Lon"/> </form> and a Java Script used to get latitude and longitude: function usePointFromPostcode(postcode, callbackFunction) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); document.forms['latlon'].lat.value=resultLat; document.forms['latlon'].lon.value=resultLng; callbackFunction(point); }else{ alert("Postcode not found!"); } }); localSearch.execute(postcode + ", UK"); } function usePointFromPostcode1(postcode1, callbackFunction) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); document.forms['latlon'].lat1.value=resultLat; document.forms['latlon'].lon1.value=resultLng; callbackFunction(point); }else{ alert("Postcode not found!"); } }); localSearch.execute(postcode1 + ", UK"); } I'm totaly stuck here. What do i do wrong? Will appreciate any help and thank you in advance.
  22. Thanks a lot AyKay47 ! Just added line below to my code before the query, and it works .. great ! $messageorder = mysql_real_escape_string($messageorder); mysql_query ("INSERT INTO orders (id, datestamp, timestamp, supplier, ordertext, delivery ) VALUES ('', '$datestamp', '$timestamp', '$supplier', '$messageorder', '$delivery')"); This really helps a lot, thanks one more time!
  23. Hallo I'm having a problem inserting $messageorder into mysql datebase. Otherwise works good. So there is no problem with database itself or mysql command too. I suspect there must be something in this code that mysql doesnt like. Also have to say that im able to sent email with $messageorder. Please take a look at the codee. $messageorder = "\r\n" . 'Order:' . '<br><br><table>' . "\r\n"; $result3 = mysql_query("SELECT * FROM orderslist WHERE supplier='$supplier'") or die(mysql_error()); $data = array(); $data['' . $row3['id']] = $_POST['' . $row3['id']]; while($row3=mysql_fetch_array($result3)) { $value = $_POST['' . $row3['id']]; if ( $value == ""){ } else { $messageorder .= " <tr> <td class='H4'><strong>$row3[name]</strong></td> <td class='H4' align='center'>$value</td> <td class='H4'>$row3[unit]</td> </tr> "; } } $messageorder .= "</table>"; echo $messageorder; date_default_timezone_set('Europe/London'); $supplier=$_GET['order']; $delivery=$_POST['delivery']; $timestamp = date("H:i:s"); $datestamp = date('Y/m/d'); mysql_query ("INSERT INTO orders (id, datestamp, timestamp, supplier, ordertext, delivery ) VALUES ('', '$datestamp', '$timestamp', '$supplier', '$messageorder', '$delivery')"); If someone could help to find a solution I will appriciate ! Thank you very much
  24. Found the problem New code looks like this: setlocale(LC_ALL, 'nl_NL'); $datestamp=$_POST['datestamp']; echo "$datestamp"; echo strftime('%A', strtotime($datestamp)); but im about to check with your setting too.. Thank you
×
×
  • 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.