Jump to content

Barand

Moderators
  • Posts

    24,584
  • Joined

  • Last visited

  • Days Won

    826

Everything posted by Barand

  1. or $d = '6/8/2013 1:01:27 PM'; list($m, $d, $y, $h, $i, $s, $a) = sscanf($d, '%d/%d/%d %d:%d:%d %s'); echo sprintf('%4d-%02d-%02d %02d:%02d:%02d', $y, $m, $d, $a=='AM'?$h:$h+12, $i, $s); //--> 2013-06-08 13:01:27
  2. If group and m are column names, use backticks ` and not single quotes UPDATE users SET `group` = 9 WHERE `m` < 5 AND `group` = 8 Don't quote numbers, only string values. group is a reserved word and should be avoided as a column name.
  3. Don't. Instead of +--------------+--------------+-----------------+---------------+ | Time | Type | Address | Codes | +--------------+--------------+-----------------+---------------+ | 11:23:26 PM | MEDICAL | 41ST ST | E19, M12 | | 10:45:26 PM | MEDICAL | MAIN ST | E20, M62, T20 | | 09:49:19 PM | RESCUE | BROADWAY AVE | E27 | +--------------+--------------+-----------------+---------------+ normalize your data correctly like this Table1 +----+--------------+--------------+-----------------+ | Id | Time | Type | Address | +----+--------------+--------------+-----------------+ | 1 | 11:23:26 PM | MEDICAL | 41ST ST | | 2 | 10:45:26 PM | MEDICAL | MAIN ST | | 3 | 09:49:19 PM | RESCUE | BROADWAY AVE | +----+--------------+--------------+-----------------+ Table2 +----+--------------+----------+ | Id | Table1_id | Code | +----+--------------+----------+ | 1 | 1 | E19 | | 2 | 1 | M12 | | 3 | 2 | E20 | | 4 | 2 | M62 | | 5 | 2 | T20 | | 6 | 3 | E27 | +----+--------------+----------+
  4. To do what, precisely?
  5. You say you intend to store the data in a database table. I hope you are NOT considering storing values like "E20, M31" in a single field. This should do it $data = array ( array('11:23:26 PM' , 'MEDICAL' , '41ST ST' , 'E19'), array('11:23:26 PM' , 'MEDICAL' , '41ST ST' , 'M12'), array('10:45:26 PM' , 'MEDICAL' , 'MAIN ST' , 'E20'), array('10:45:26 PM' , 'MEDICAL' , 'MAIN ST' , 'M62'), array('10:45:26 PM' , 'MEDICAL' , 'MAIN ST' , 'T20'), array('09:49:19 PM' , 'RESCUE' , 'BROADWAY AVE' , 'E27') ); $new = array(); foreach ($data as $arr) { $key = join('|', array_slice($arr,0,3)); if (isset($new[$key])) { $new[$key][3][] = $arr[3]; } else { $new[$key] = array ($arr[0], $arr[1], $arr[2], array($arr[3])); } } echo '<pre>'; foreach ($new as $arr) { printf("%-12s | %-12s | %-15s | %s\n", $arr[0], $arr[1], $arr[2], join(', ', $arr[3])); } echo '</pre>'; /****************** RESULT *********************************** 11:23:26 PM | MEDICAL | 41ST ST | E19, M12 10:45:26 PM | MEDICAL | MAIN ST | E20, M62, T20 09:49:19 PM | RESCUE | BROADWAY AVE | E27 **************************************************************/
  6. SELECT IF(datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW(), 0, 1) as olderThan3mins ...
  7. use array_filter $array = array(0,0,0,0,0,1,2,3); $found = array_filter($array); echo '<pre>',print_r($found, true),'</pre>'; /** result Array ( [5] => 1 [6] => 2 [7] => 3 ) */ edit : or list($nonZeroKey,$value) = each(array_filter($array));
  8. Search for rows WHERE datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW()
  9. You are not running the query, just defining a string function get_store_by_id($store_id) { $query = "SELECT * FROM stores WHERE id = {$store_id} "; $result = mysql_query($query); return $result; }
  10. and if $name is a string value it needs to be in single quotes $qury="select * from admin where name='$name' ";
  11. Syntax for IN is a comma-separated list eg IN (1,2,3) It looks like your $var_hook is an array, so $id_list = join(',', $var_hook); then use IN ($id_list)
  12. This thread should help http://forums.phpfreaks.com/topic/277085-the-eav-model-or-something-better/
  13. See forum FAQ http://forums.phpfreaks.com/index.php?showtopic=273121
  14. Sean Murray has 32 yes/no values so there is not a consistent pattern edit: Also fran and roxy have single-word names
  15. try echo "<option value=\"{$row['csname']}\">{$row['csname']}</option>";
  16. See "MySQL Table aliases". Most of the time they are an optional convenience but in some cases they are essential.
  17. see this site's FAQ http://forums.phpfreaks.com/index.php?showtopic=273121
  18. The problem with resizing on the client, either HTML or CSS, is that you are still downloading the full-size image which takes time. If I'm going to require thumbnails I prefer to create them on upload then they are available for speedy download and display.
  19. To find records in votes with no matching poll_id in user_votes use a left join. SELECT v.* FROM votes v LEFT JOIN user_votes uv ON v.poll_id = uv.vote_poll_id WHERE v.user_id = 1 AND uv.vote_poll_id IS NULL
  20. What gets updated when a user votes?
  21. perhaps @VAL := LAST_INSERT_ID(); INSERT INTO `otherTb` (user_id, `instance_id`, `category_id`,) VALUES (@VAL, NULL, 04);
  22. which of those 2 tables, votes or user_votes, does NOT have a poll_id until the user votes?
  23. All 3 of them
  24. 1 You need all the items being voted on so you know which are missing 2. You need all users so you know who has not voted 3. You need which user voted for which item
×
×
  • 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.