Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. That's what I was wondering but they were deprecated over a decade ago
  2. 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>';
  3. 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
  4. Hoangthi Have you set your default timezone? http://php.net/manual/en/function.date-default-timezone-set.php
  5. Unfortunately, most people I know here in the UK would write the date as d/m/y
  6. 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
  7. Barand

    Database help

    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
  8. 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?
  9. Foreign keys require InnoDB tables. If yours are MyIsam then it won't work.
  10. 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.
  11. Use ( )s SELECT * FROM `videos` WHERE `time` > '600' AND (`tags` LIKE '%play%' OR `tags` LIKE '%soccer%' OR `tags` LIKE '%ronaldo%')
  12. 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";
  13. It becomes totally confusing once one looks at your sample group ids, which bear little resemblance to to your description of the id structure
  14. 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.
  15. The inner subquery needs to be SELECT MAX(last_visit) as last_visit FROM clubvisit WHERE dues IS NOT NULL
  16. 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
  17. Yep, a second pair of eyes often helps
  18. ???
  19. Think? Have you not tested it?
  20. mysql_select_db($db); you are using mysqli
  21. In what way does it not want to work?
  22. 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)
  23. 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 | +--------+------+---------------------+--------+
  24. 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?
  25. 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
×
×
  • 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.