-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
"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
- 19 replies
-
- not exists
- rand()
-
(and 1 more)
Tagged with:
-
Printing Multidimensional Arrays with C Style For Loop
Barand replied to juuuugroid's topic in PHP Coding Help
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>'; -
Most common storage format is "YYYY-MM-DD HH:NN:SS"
-
"6/8/2013 1:02:37 AM" converted to unix timestamp
Barand replied to gamefreak13's topic in PHP Coding Help
Don't store your dates as unix timestamps - store them as type DATETIME, format "yyyy-mm-dd hh:ii:ss" -
"6/8/2013 1:02:37 AM" converted to unix timestamp
Barand replied to gamefreak13's topic in PHP Coding Help
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 -
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.
-
Combine Overly-Redundant Table Of Data (PHP/MySQL)
Barand replied to gamefreak13's topic in PHP Coding Help
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 | +----+--------------+----------+ -
To do what, precisely?
-
Combine Overly-Redundant Table Of Data (PHP/MySQL)
Barand replied to gamefreak13's topic in PHP Coding Help
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 **************************************************************/ -
SELECT IF(datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW(), 0, 1) as olderThan3mins ...
-
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));
-
Search for rows WHERE datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW()
-
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; }
-
and if $name is a string value it needs to be in single quotes $qury="select * from admin where name='$name' ";
-
-
Arrays from MySQL database contains no data? (Simple Q)
Barand replied to rjt90's topic in PHP Coding Help
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) -
This thread should help http://forums.phpfreaks.com/topic/277085-the-eav-model-or-something-better/
-
See forum FAQ http://forums.phpfreaks.com/index.php?showtopic=273121
-
Sean Murray has 32 yes/no values so there is not a consistent pattern edit: Also fran and roxy have single-word names
-
try echo "<option value=\"{$row['csname']}\">{$row['csname']}</option>";
-
See "MySQL Table aliases". Most of the time they are an optional convenience but in some cases they are essential.
- 19 replies
-
- not exists
- rand()
-
(and 1 more)
Tagged with:
-
Getting Error Before Installing PHP Script ( Mysql Database Connection Error )
Barand replied to Venky's topic in MySQL Help
see this site's FAQ http://forums.phpfreaks.com/index.php?showtopic=273121 -
Is there any programming standards for resizing images in PHP?
Barand replied to angel1987's topic in Application Design
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.- 4 replies
-
- image resize
- images
-
(and 2 more)
Tagged with:
-
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
- 19 replies
-
- not exists
- rand()
-
(and 1 more)
Tagged with:
-
What gets updated when a user votes?
- 19 replies
-
- not exists
- rand()
-
(and 1 more)
Tagged with: