Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Instead of hard-coding the required column names as in $fields = array('id','lat','lon','name','amenity','operator','vending'); you could use this to pick up any additional columns added to your pois table $sql = "SHOW COLUMNS FROM pois"; $fields = array(); $res = $db->query($sql); while ($row = $res->fetch_row()) { $fields[] = $row[0]; }
  2. Barand

    SUM in record

    http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_sum
  3. Barand

    SUM in record

    Yes but, for the second part of your question, you need to install Intel's new telepathy chip.
  4. Do you mean like this? $xmlstr = <<<XML <data> <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> </data> XML; $fields = array('id','lat','lon','name','amenity','operator','vending'); $xml = simplexml_load_string($xmlstr); $dbdata = array(); foreach ($xml->node as $node) { $nodedata = array_fill_keys($fields,''); $nodedata['id'] = $node['id']; $nodedata['lat'] = isset($node['lat']) ? $node['lat'] : 0; $nodedata['lon'] = isset($node['lon']) ? $node['lon'] : 0; foreach ($node->tag as $tag) { $k = (string)$tag['k']; $v = (string)$tag['v']; if (isset($nodedata[$k])) { $nodedata[$k] = $v; } } $dbdata[] = vsprintf("(%d, %10.7f, %10.7f, '%s', '%s', '%s', '%s')", $nodedata); } $fieldlist = join(',', $fields); $sql = "REPLACE INTO pois ($fieldlist) VALUES\n" . join(",\n", $dbdata); echo "<pre>$sql</pre>"; $db->query($sql);
  5. Sample data +----+---------------------+ | id | viewtime | +----+---------------------+ | 1 | 2014-05-25 00:03:00 | | 2 | 2014-05-25 00:05:00 | | 3 | 2014-05-25 00:10:00 | | 4 | 2014-05-25 00:20:00 | | 5 | 2014-05-25 00:29:00 | | 6 | 2014-05-25 00:39:00 | | 7 | 2014-05-25 00:48:00 | | 8 | 2014-05-25 00:52:00 | | 9 | 2014-05-25 00:59:00 | | 10 | 2014-05-25 01:05:00 | ... |491 | 2014-05-26 23:06:00 | |492 | 2014-05-26 23:15:00 | |493 | 2014-05-26 23:23:00 | |494 | 2014-05-26 23:32:00 | |495 | 2014-05-26 23:42:00 | |496 | 2014-05-26 23:44:00 | |497 | 2014-05-26 23:51:00 | |498 | 2014-05-26 23:57:00 | |499 | 2014-05-26 23:58:00 | +----+---------------------+ Get counts per hour each day then get the average count SELECT date, AVG(hourtot) as daily_av_per_hr FROM ( SELECT DATE(viewtime) as date , HOUR(viewtime) as hr , COUNT(*) as hourtot FROM blog GROUP BY date, hr ) tots GROUP BY date +------------+-----------------+ | date | daily_av_per_hr | +------------+-----------------+ | 2014-05-25 | 10.5417 | | 2014-05-26 | 10.2500 | +------------+-----------------+
  6. try SELECT rider_name , rides , pts , pos FROM ( SELECT COUNT( `points` ) AS 'rides' , SUM( `points` ) AS 'pts' , rider_name , @serial := @serial +1 AS pos FROM tbl_heat JOIN (SELECT @serial :=0) AS init WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESC ) as sorted
  7. now() shouldn't have quotes round it in the query
  8. What, you aren't storing your data in a series of spreadsheets?
  9. Do I sniff a homework assignment here?
  10. Your data base design is creating your problems and is in serious need of normalization See http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360
  11. It would suggest "a_code" is defined as unique key and you have two (or more) records in your data with the same value "00-SBN2" in that field
  12. You cannot be serious!
  13. The way to do it is to give the duplicate column names a column alias. You should NOT be using "SELECT * " anyway, but specifying the columns that you want (except in rare situations where you really do want every column, or maybe when testing).
  14. Check for errors. mysql_query($sql, $conn) or die(mysql_error() . "<pre>$sql</pre>"); And use the forum's code tags when posting code.
  15. Also Use a while loop and not do..while() otherwise the first record isn't read until the end of the first iteration. Use mysql_real_escape_string() instead of addslashes() (Better still, use mysqli or PDO)
  16. If you just want to know if the keys and values are the same a simple equality check will do it $a = array('q1' => 'no', 'q3' => 'yes', 'q2' => 'yes'); $b = array('q1' => 'no', 'q2' => 'yes', 'q3' => 'yes'); echo $a == $b ? "Arrays are the same" : "Arrays are different";
  17. In particular http://www.php.net/manual/en/ref.datetime.php
  18. Use DateTime objects $data = array('1:52:37','9:56:39','08:04:22','05:32:20'); echo addTimes($data); //--> 1 days 1 hrs 25 mins 58 secs echo "<br/>"; echo subtractTime('18:33:20','11:40:30'); //--> 0 days 6 hrs 52 mins 50 secs function addTimes ($data) { $dt = new DateTime(); $dt->setTimestamp(0); $dt2 = clone $dt; foreach ($data as $t) { list ($h,$m,$s) = explode(':',$t); $di = new DateInterval("PT{$h}H{$m}M{$s}S"); $dt->add($di); } return $dt->diff($dt2)->format('%d days %h hrs %i mins %s secs'); } function subtractTime($t1, $t2) { $dt1 = new DateTime(); list ($h,$m,$s) = explode(':',$t1); $dt1->setTime($h, $m, $s); $dt2 = new DateTime(); list ($h,$m,$s) = explode(':',$t2); $dt2->setTime($h, $m, $s); return $dt1->diff($dt2)->format('%d days %h hrs %i mins %s secs'); }
  19. Wasn't sure if going to take my advice. In that case, to get you started, here is an SQL script file to create the tables and some test data for you mythri.sql.txt
  20. I would have two tables +------------+ | user | +------------+ +------------+ | userid |-----+ | family | | name | | +------------+ +------------+ | | id | | | membername | +-------<| userid | +------------+ then any user can have as few or many family members as they need. No arbitrary limits because you allowed 50 columns. (Sorry, Psycho. I refreshed before typing and you weren't there)
  21. What you have is completely different type of problem. In the original post it was only necessary to have displayed the new link when the page loaded. You want it to be done while the page is loaded. This will require javascript or AJAX. The simplest way would be to create a javascript array and use setInterval() to fetch and display the next element every 30 seconds. If you are going to hijack someone else's thread, be sure of the problem.
  22. See what mysql_error() has to say about it.
  23. Find the players who played on that date (subquery) then match against those players with a join to the subquery SELECT ap.playerID, COUNT(ap.matchID) as total FROM appearances ap INNER JOIN ( SELECT a.playerID FROM match m INNER JOIN appearances a ON m.matchID = a.appearanceMatchID WHERE m.matchDate = '$matchdate' ) selected USING (playerID) GROUP BY ap.playerID
  24. Always escape user data before you use it in a query. The %s should be inside the the quotes with the search term. $busca = mysql_real_escape_string($_POST['busca']); $result = mysql_query("SELECT * FROM `users` WHERE CONCAT(Nom, ' ', cognoms) like '%$busca%' "); I would advise you move to MYSQLi or PDO if you don't want to rewrite all your code next time you upgrade PHP
  25. These two samples draw a square within an outer square. A fill is applied from just inside the top left corner of each square. gd1 - the fills are applied then the lines are added gd2 - the lines are added before the fills are applied. Not surprisingly, events occur in the order they are coded gd1.php <?php $im = imagecreate(200,200); $bg = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $bk = imagecolorallocate($im, 0, 0, 0); $rd = imagecolorallocate($im, 0xCC, 0, 0); $bl = imagecolorallocate($im, 0, 0, 0xCC); imagerectangle($im, 0, 0, 199, 199, $bk); imagesetthickness($im, 2); imagerectangle($im, 50, 50, 150, 150, $bk); // add fills imagefill($im, 2, 2, $rd); imagefill($im, 52, 52, $bl); // add lines imageline($im, 100, 0, 100, 199, $bk); imageline($im, 0, 100, 199, 100, $bk); // output header("Content-type: image/png"); imagepng($im); imagedestroy($im); gd2.php <?php $im = imagecreate(200,200); $bg = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $bk = imagecolorallocate($im, 0, 0, 0); $rd = imagecolorallocate($im, 0xCC, 0, 0); $bl = imagecolorallocate($im, 0, 0, 0xCC); imagerectangle($im, 0, 0, 199, 199, $bk); imagesetthickness($im, 2); imagerectangle($im, 50, 50, 150, 150, $bk); // add lines imageline($im, 100, 0, 100, 199, $bk); imageline($im, 0, 100, 199, 100, $bk); // add fills imagefill($im, 2, 2, $rd); imagefill($im, 52, 52, $bl); // output header("Content-type: image/png"); imagepng($im); imagedestroy($im);
×
×
  • 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.