-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
That's what I was wondering but they were deprecated over a decade ago
-
Why do none of your checkboxes have different values? In the processing page, what does this output when the form is submitted echo '<pre>', print_r($_POST, 1), '</pre>';
-
try function secs2parts($secs) { $days = floor($secs/86400); $s = $secs % 86400; $hours = floor($s/3600); $s = $s % 3600; $mins = floor($s/60); $s = $s % 60; return array( 'days' => $days, 'hrs' => $hours, 'mins' => $mins, 'secs' => $s ); } foreach (secs2parts(361764) as $k=>$v) { if ($v) echo "$v$k "; } // --> 4days 4hrs 29mins 24secs
-
Hoangthi Have you set your default timezone? http://php.net/manual/en/function.date-default-timezone-set.php
-
Unfortunately, most people I know here in the UK would write the date as d/m/y
-
Store datetimes in "yyyy-mm-dd hh:ii:ss" format in DATETIME type columns. That way they are searchable, sortable, can be compared with other dates and, pertinent to this instance, you can use MySQL's date arithmetic functionality. In other words the correct format is useful, yours is not. If you want to do SQL arithmetic on your format you have the additional overhead of converting it from a string to the correct date format and back again SELECT DATE_FORMAT( STR_TO_DATE('21-10-2013 14:30:00', '%d-%m-%Y %H:%i:%s') + INTERVAL 5 DAY + INTERVAL 1 HOUR, '%d-%m-%Y %H:%i:%s') as newtime; +---------------------+ | newtime | +---------------------+ | 26-10-2013 15:30:00 | +---------------------+ Or you can do it in the PHP code $dt = DateTime::createFromFormat('d-m-Y H:i:s', '21-10-2013 14:30:00'); $dt->add(new DateInterval('P5DT1H')); echo $dt->format('d-m-Y H:i:s'); // --> 26-10-2013 15:30:00
-
Avoid spaces in column names. Don't duplicate values like University Name in every record. Normalize the data http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360
-
try ALTER TABLE Klasse ADD CONSTRAINT `fk_klassecode` FOREIGN KEY (klassekode) REFERENCES Student(klassekode) but are you sure you don't want to add the FK to student table, referencing the Klasse table's PK?
-
Foreign keys require InnoDB tables. If yours are MyIsam then it won't work.
-
These are broadly the steps I take when embarking on a project - Define all the processes that will be required for now and also the longer term (wish list). - Define all the data that will be required to support those processes. - Construct a relational data model. - Design the processes and validate that the model is viable for the processes (ie required data is there and accessible) - Then start coding with confidence that you won't need considerable rewriting.
-
Use ( )s SELECT * FROM `videos` WHERE `time` > '600' AND (`tags` LIKE '%play%' OR `tags` LIKE '%soccer%' OR `tags` LIKE '%ronaldo%')
-
1. BACK UP YOUR TABLE 2. Run this update query to strip the " sec" from the time column values. UPDATE videos SET time = SUBSTRING_INDEX(time,' ',1); 3 Now change the column type to INT with ALTER TABLE `videos` CHANGE COLUMN `time` `time` INT NULL DEFAULT NULL ; Your query should now work if all the times were in the same format "999 sec";
-
It becomes totally confusing once one looks at your sample group ids, which bear little resemblance to to your description of the id structure
-
PHP select from database and compare result Problem
Barand replied to IlaminiAyebatonyeDagogo's topic in PHP Coding Help
Your code searches for rows where pin = password then goes on to check if the pin in found rows is equal to the password. Waste if time - if it finds them they must be equal. -
selecting/searching rows of a Table based on the value of a field in the table.
Barand replied to ajoo's topic in MySQL Help
The inner subquery needs to be SELECT MAX(last_visit) as last_visit FROM clubvisit WHERE dues IS NOT NULL- 22 replies
-
- 1
-
- ajoo
- conditional search query
-
(and 1 more)
Tagged with:
-
selecting/searching rows of a Table based on the value of a field in the table.
Barand replied to ajoo's topic in MySQL Help
Some things are easier in the script include ("/db_inc.php"); $db=new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $sql = "SELECT day_id, dues, last_visit, points FROM clubvisit ORDER BY last_visit DESC"; $res = $db->query($sql); $val = $nextval = 0; $results = array(); $row = $res->fetch_assoc(); // get first row $val = $row['dues']; do { if ($row['dues'] != $val) { if ($nextval==0) { $val = $row['dues']; $nextval = 1; } else break; } $results[] = $row; } while ($row = $res->fetch_assoc()); $results = array_reverse($results); echo '<pre>'; foreach ($results as $rec) { echo join("\t", $rec)."\n"; } echo '</pre>'; RESULTS 3 600 2012-12-07 10:00:00 4 4 600 2012-12-09 21:00:00 6 5 600 2012-12-10 15:00:00 6 7 600 2012-12-10 20:00:00 6 6 500 2012-12-14 17:00:00 5 8 500 2012-12-14 19:30:00 5- 22 replies
-
- ajoo
- conditional search query
-
(and 1 more)
Tagged with:
-
Yep, a second pair of eyes often helps
-
???
-
Think? Have you not tested it?
-
mysql_select_db($db); you are using mysqli
-
In what way does it not want to work?
-
When you GROUP BY tradeshow_id you get a single row for each value of tradeshow_id. Columns that are selected but which are not aggregated nor in the group by clause could, according to the manual, come from any record in the group but usually from the first (which is why you get primary_id of 1). If you want the primary_id and user_id to come from the record that contains the MAX date then you need a JOIN on the id and date SELECT s.primary_id, s.user_id, s.date, s.tradeshow_id FROM comments as s INNER JOIN ( SELECT tradeshow_id, MAX(date) as date FROM comments GROUP BY tradeshow_id ) as m USING (tradeshow_id, date)
-
selecting/searching rows of a Table based on the value of a field in the table.
Barand replied to ajoo's topic in MySQL Help
With my data above, this might be what you want SELECT day_id, dues, last_visit, points FROM clubvisit JOIN ( SELECT cv.dues FROM clubvisit cv JOIN ( SELECT dues as lastdues FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) as A ON cv.dues >= A.lastdues GROUP BY cv.dues LIMIT 2 ) duesvalues USING (dues) ORDER BY last_visit; Which gives +--------+------+---------------------+--------+ | day_id | dues | last_visit | points | +--------+------+---------------------+--------+ | 3 | 600 | 2012-12-07 10:00:00 | 4 | | 4 | 600 | 2012-12-09 21:00:00 | 6 | | 5 | 600 | 2012-12-10 15:00:00 | 6 | | 7 | 500 | 2012-12-10 20:00:00 | 5 | | 6 | 600 | 2012-12-14 17:00:00 | 6 | | 8 | 500 | 2012-12-14 19:30:00 | 5 | +--------+------+---------------------+--------+- 22 replies
-
- ajoo
- conditional search query
-
(and 1 more)
Tagged with:
-
selecting/searching rows of a Table based on the value of a field in the table.
Barand replied to ajoo's topic in MySQL Help
With one person entering data serially it is still possible to accidentally miss one then enter it later. With more than one person there is no guarantee at all of maintaining the sequence. If you have two records for 14/12 there is now way of knowing which was the later, therefore you need a time element DROP TABLE IF EXISTS `clubvisit`; CREATE TABLE `clubvisit` ( `day_id` int(11) NOT NULL AUTO_INCREMENT, `dues` int(11) DEFAULT NULL, `last_visit` datetime DEFAULT NULL, `points` int(11) DEFAULT NULL, PRIMARY KEY (`day_id`) ) ; INSERT INTO `clubvisit` VALUES (1,900,'2012-12-01 20:00:00',6), (2,700,'2012-12-04 17:00:00',7), (3,600,'2012-12-07 10:00:00',4), (4,600,'2012-12-09 21:00:00',6), (5,600,'2012-12-10 15:00:00',6), (6,600,'2012-12-14 17:00:00',6), (7,500,'2012-12-10 20:00:00',5), (8,500,'2012-12-14 19:30:00',5); Sorted into time order we now have +--------+------+---------------------+--------+ | day_id | dues | last_visit | points | +--------+------+---------------------+--------+ | 1 | 900 | 2012-12-01 20:00:00 | 6 | | 2 | 700 | 2012-12-04 17:00:00 | 7 | | 3 | 600 | 2012-12-07 10:00:00 | 4 | | 4 | 600 | 2012-12-09 21:00:00 | 6 | | 5 | 600 | 2012-12-10 15:00:00 | 6 | | 7 | 500 | 2012-12-10 20:00:00 | 5 | | 6 | 600 | 2012-12-14 17:00:00 | 6 | | 8 | 500 | 2012-12-14 19:30:00 | 5 | +--------+------+---------------------+--------+ So given this data, what was the question again, and what would be the expected result?- 22 replies
-
- ajoo
- conditional search query
-
(and 1 more)
Tagged with:
-
new DateTime($date) requires $date to be in yyyy-mm-dd format. To create a DateTime object from other formats use http://www.php.net/manual/en/datetime.createfromformat.php