-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Your code has quotes missing. Notice the color of the text in the code box above?
-
Use code tags.
-
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
Does it work if you link to a local jquery.js file instead of the google one? -
You might use PHP to get the lat/long data via AJAX but communication with maps api would use javascript. https://developers.google.com/maps/documentation/javascript/examples/polyline-simple
-
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
Are any of the jQuery calls functioning? -
Extracting only specific array elements
Barand replied to NotionCommotion's topic in PHP Coding Help
Possibly, it is a neat solution for those who understand the function. Another option may be to organize your query so you can use array_slice(). -
Extracting only specific array elements
Barand replied to NotionCommotion's topic in PHP Coding Help
or simply $clients[] = [ 'name' => $source['name'], 'guid' = $source['guid'] ]; [EDIT] Requinix's turn to beat me to the post -
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
Check the browser console to see if the AJAX calls are behaving -
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
That would be because the query failed // get the google maps key $sql = "SELECT gm_key , ROUND(home_lat,2) , ROUND(home_long,2) FROM mydb.google_map_key"; $res = $db->query($sql); list($gmkey, $home_lat, $home_lng) = $res->fetch_row(); As the comment says, that query fetches my personal Google API key from a database (plus the starting map coordinates for the application. I suggest you provide those three values as hard-coded values for now to get it working. Remove the above code and replace with $home_lat = 27.60; $home_lng = 77.06; $gmkey = "<your api key goes here>"; I did some more testing today. "route_2" works only if the places on the route are on a straight route IE for A - B - C - D If you go off the line as in A - B D | | \ | C then it give the time for AD as less than the time AC. So the code needs changing so, instead of calculating AB, AC, AD as it does now, it calculates AB, BC, CD and accumulates the times. Revised route2 attached. routes_2.php -
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
I haven't used the Google Distance Matrix API before so this was a learning exercise for me. Here's a small application: route_1.pgp - main page with map display route_2.php - responds to AJAX calls to retrieve data route.sql.txt - SQL script file to create database (Note mins and distances are set to zero in the route_definition table) When you load route_1, the routes are listed. Clicking on a route fetches the route definition from the database, submits a request to the google api to get the times and distances and updates the route records in the table. The distances and times are then listed on the screen and the stops are displayed on the map. I hope this helps to get you going. routes.sql.txt routes_1.php routes_2.php -
Consult the manual http://php.net/manual/en/migration70.new-features.php
-
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
https://developers.google.com/maps/documentation/distance-matrix/start -
Need help to clear Concept of Google Maps integration in PHP
Barand replied to AMITKUMAR's topic in Application Design
It looks like you have a lot of duplication of data. Every time you add a bus, you add the stops also. A better approach would be to define the route first. Route definition Stop +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | route_id | sequence | stop_id | mins | | stop_id | stop name | Lat | Long | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ | DA | 1 | 102 | 0 | | 101 | Agra | 27.16945 | 78.01194 | | DA | 2 | 103 | 10 | | 102 | Dehli | 28.60357 | 77.26217 | | DA | 3 | 104 | 190 | | 103 | Noida | etc | | DA | 4 | 101 | 250 | | 104 | Vrindavan | etc | +-----------+-----------+-----------+--------+ +----------+-----------------------+----------+-----------+ Now you can add the timetabled journeys to run on each route Timetabled journey +----------+-------------+----------+ | jny_id | route_id | depart | +----------+-------------+----------+ | 450 | DA | 7:50 | | 451 | DA | 9:50 | Intermediate stop times are then calculated from the route definition. You can take it further if you have a table to allocate the "bus working" defining the sets of journeys scheduled for a bus. This enables you to produce service timetable as well as vehicle timetables. To show on a map first create a map object. For each stop, create a LatLng object using the stop's latitude and longitude values add marker object to map object using the LatLng object [EDIT] Note that the above would be done in Javascript. You would use PHP to retrieve the data required and pass it to the client via an AJAX request. -
The input password will not match that in the user table, so your selection criteria should just be where the username matches. Then verify the retrieved password hash.
-
Is it Sunday?. It was no great hardship for me, merely bringing it to someone's notice. I was just trying to get the back-story on someone's recent post to find out what they were talking about. Please, don't stop work on my account.
-
I am unable to find anything using "Search". Similarly, clicking a members "Find Content" button shows no results.
-
How about putting a FROM clause in your query to tell it which table the data is to come from.
-
group by month and year with this format "01/29/2016"
Barand replied to Yohanne's topic in MySQL Help
Use str_to_date() to convert your format to to DATE type. Then you can use the other datetime functions on it. EG SELECT YEAR(STR_TO_DATE(datestr, '%m/%d/%Y')) as yr , MONTH(STR_TO_DATE(datestr, '%m/%d/%Y')) as mth , COUNT(*) as total FROM mytable GROUP BY yr, mth You can use the same function to update your database table with a single query. Backup the table, just in case UPDATE mytable SET datestr = STR_TO_DATE(datestr, '%m/%d/%Y'); Alter varchar to DATE -
This function will return week number 1 or 2 for a given date (today being in week 1 and changing each sunday) function myWeekNumber(DateTime $date) { $base = new dateTime('2000-01-01'); // Fixed Saturday date return ceil($date->diff($base)->days/7) % 2 + 1; }
-
Unfortunately you can have week 53 followed by week 1, so two consecutive odd week numbers. Safer to use the number of weeks elapsed from a fixed date in the past.
-
Commonly known as "Hungarian Notation" https://en.wikipedia.org/wiki/Hungarian_notation
-
Getting sum of a column from a table into a textbox
Barand replied to lindisfarne's topic in PHP Coding Help
Are you referring to an input box of type "text" or a textarea element? If the former then using the value attribute should work. echo "<input type='text' name='total' value='$total' />"; If you mean the latter then there is no value attribute. The text content goes between the open and close tags echo "<textarea rows='2' cols='20' name='total'>$total</textarea>"; Basic HTML. And please use code tags, or the "<>" button in the toolbar. -
A homeless snail ?
-
This closes off any current tags $text = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam elementum ornare scelerisque.<br> <a href='xyz.com' target='_blank'>Vestibulum</a> iaculis mattis dui.</p> <p>Aliquam <i>scelerisque</i> sapien at tellus accumsan varius. <img src='a.jpg'> Fusce facilisis ullamcorper dapibus. Aliquam dignissim</p> <ul> <li>gravida</li> <li>dui eget</li> <li>aliquam</li> </ul> <p>Duis odio, semper eu sodales vel, sollicitudin eu enim. Cras tortor libero, pellentesque accumsan tempus in, ullamcorper nec augue. Mauris eu ipsum mauris, non imperdiet ipsum. In hac habitasse platea dictumst. Morbi ipsum mauris, tincidunt vitae pretium tempor, pretium a turpis. Nulla quis eros eu lorem aliquam congue non a nisl.</p>"; $voidtags = ['br','hr','img']; $keeptags = '<a><b><i><br><p><ul><ol><li><u><strong><emphasis>'; $limit = 30; $summary = limitText($text, $limit, $voidtags, $keeptags); echo $summary; function limitText($text, $limit, $voidtags, $keeptags) { $result = ''; $p=0; $tags=[]; $currtag = ''; $words = 0; $intag = $inword = 0; $text = strip_tags($text, $keeptags); $len = strlen($text); while ($p<$len) { $c = $text[$p]; switch ($c) { case '<': if ($inword) { $inword = 0; $words++; if ($words > $limit) break 2; } $intag = 1; break; case '>': if ($intag && $currtag != '') { if (!in_array($currtag, $voidtags)) $tags[] = $currtag; $currtag = ''; } $intag = 0; break; case '/': if ($intag) { array_pop($tags); do { $result .= $c; } while (($c=$text[++$p]) !='>'); $intag = 0; } break; case "\n": case "\t": case ' ': if ($inword) { $inword = 0; $words++; if ($words >= $limit) break 2; } elseif ($intag) { $tags[] = $currtag; do { $result .= $c; } while (($c=$text[++$p]) !='>'); $intag = 0; } break; default: if ($intag) { $currtag .= $c; } else $inword = 1; break; } $result .= $c; ++$p; } while ($t=array_pop($tags)) { $result .= "</{$t}>"; // close any open tags } return $result; } results <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam elementum ornare scelerisque.<br> <a href="xyz.com" target="_blank">Vestibulum</a> iaculis mattis dui.</p> <p>Aliquam <i>scelerisque</i> sapien at tellus accumsan varius. Fusce facilisis ullamcorper dapibus. Aliquam dignissim</p> <ul> <li>gravida</li> <li>dui</li></ul>