Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. "WHERE" selection conditions on a left-joined table need to be part of the join. Try SELECT v.* FROM votes v LEFT JOIN user_votes uv ON v.poll_id = uv.vote_poll_id AND uv.voter_id = $id WHERE v.user_id != $id AND uv.vote_poll_id IS NULL ORDER BY RAND() LIMIT 1
  2. Just as you would in C echo '<pre>'; for ($i=0, $k=count($fileinfo); $i < $k; $i++) { printf ("%3d\t%8d\t%-15s\n", $i, $fileinfo[$i][0], $fileinfo[$i][1]); } echo'</pre>';
  3. Most common storage format is "YYYY-MM-DD HH:NN:SS"
  4. Don't store your dates as unix timestamps - store them as type DATETIME, format "yyyy-mm-dd hh:ii:ss"
  5. 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
  6. 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.
  7. 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 | +----+--------------+----------+
  8. To do what, precisely?
  9. 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 **************************************************************/
  10. SELECT IF(datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW(), 0, 1) as olderThan3mins ...
  11. 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));
  12. Search for rows WHERE datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW()
  13. 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; }
  14. and if $name is a string value it needs to be in single quotes $qury="select * from admin where name='$name' ";
  15. 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)
  16. This thread should help http://forums.phpfreaks.com/topic/277085-the-eav-model-or-something-better/
  17. See forum FAQ http://forums.phpfreaks.com/index.php?showtopic=273121
  18. Sean Murray has 32 yes/no values so there is not a consistent pattern edit: Also fran and roxy have single-word names
  19. try echo "<option value=\"{$row['csname']}\">{$row['csname']}</option>";
  20. See "MySQL Table aliases". Most of the time they are an optional convenience but in some cases they are essential.
  21. see this site's FAQ http://forums.phpfreaks.com/index.php?showtopic=273121
  22. 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.
  23. 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
  24. What gets updated when a user votes?
×
×
  • 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.