anonīms Posted August 4, 2010 Report Share Posted August 4, 2010 trase1+t1.trase2+t1.trase3+t1.trase4+t1.trase5+t1.trase5 AS summa_laiks trase1 - 18:15; trase2 - 05:02; Kopā jābut - 23:17 Problēma ir tāda, ka uzrādas nevis kā 23:17, bet gan 2317 (echo summa_laiks) Kur varētu būt vaina? Quote Link to comment Share on other sites More sharing options...
Леший Posted August 4, 2010 Report Share Posted August 4, 2010 + zīme kasto uz decimal. būs jāņēmās ar substr, vēl labāk uzrakstīt funkciju. Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 4, 2010 Author Report Share Posted August 4, 2010 Okey. function trashu_laiks($laiks) { if($laiks == '0') return '00:00'; $sekundes = substr($laiks, -2); $minutes = substr($laiks, 0, -2); $laiks = $minutes.':'.$sekundes; return $laiks; } Quote Link to comment Share on other sites More sharing options...
Леший Posted August 4, 2010 Report Share Posted August 4, 2010 Nav paredzēta situācija, kad $sekundes > 59 Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 4, 2010 Author Report Share Posted August 4, 2010 Tāda situācija arī nevar būt :] Quote Link to comment Share on other sites More sharing options...
waplet Posted August 4, 2010 Report Share Posted August 4, 2010 Kāpec gan nē? saskaiti 18:30 + 2:31 Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 5, 2010 Author Report Share Posted August 5, 2010 njā :/ 28:61 Bet kādēļ tas time netiek saskaitīts normāli, jo 28:61 nāk pa taisno kā summa_laiks (ar +++++ ) Quote Link to comment Share on other sites More sharing options...
marcis Posted August 5, 2010 Report Share Posted August 5, 2010 mysql> SELECT CAST(CAST('18:15:00' AS time)+CAST('05:02:00' AS time) AS time); +-----------------------------------------------------------------+ | CAST(CAST('18:15:00' AS time)+CAST('05:02:00' AS time) AS time) | +-----------------------------------------------------------------+ | 23:17:00 | +-----------------------------------------------------------------+ 1 row in set (0.00 sec) Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 5, 2010 Author Report Share Posted August 5, 2010 Laikam esmu kkur kko nolaidis grieizi. Neizvadās 'time' $kaarta1 = mysql_query("SELECT t1.*, CAST(CAST(t1.trase1 AS time)+CAST(t1.trase2 AS time)+CAST(t1.trase3 AS time)+CAST(t1.trase4 AS time)+CAST(t1.trase5 AS time)+CAST(t1.trase6 AS time) AS time) AS time, t2.lietotajvards AS users FROM ".PREFIX."racing_rezultati AS t1, ".PREFIX."lietotaji AS t2 WHERE t1.t_id = '".$tourney['id']."' AND t1.user_id = t2.id AND t1.karta = 1 ORDER BY time ASC") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
marcis Posted August 5, 2010 Report Share Posted August 5, 2010 Ja time ir kolonas nosaukums (vai alias), tad to vajēdzētu likt apostrofos (vai nezinu kā viņus tur sauc) -> `time` Ja kolonas tips jau ir time, tad tas jākāsto uz time :) Parādi CREATE TABLE iesaistītajām tabulām. Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 5, 2010 Author Report Share Posted August 5, 2010 CREATE TABLE IF NOT EXISTS `racing_rezultati` ( `id` int(11) NOT NULL auto_increment, `t_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `trase1` time NOT NULL, `trase2` time NOT NULL, `trase3` time NOT NULL, `trase4` time NOT NULL, `trase5` time NOT NULL, `trase6` time NOT NULL, `karta` tinyint(1) NOT NULL default '1', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ; -- -- Dumping data for table `bliezamv3_racing_rezultati` -- INSERT INTO `racing_rezultati` (`id`, `t_id`, `user_id`, `trase1`, `trase2`, `trase3`, `trase4`, `trase5`, `trase6`, `karta`) VALUES (1, 523, 1, '00:18:15', '00:05:02', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (2, 523, 147, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (3, 523, 349, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (4, 523, 145, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (5, 523, 159, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (6, 523, 198, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (7, 523, 405, '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1), (8, 523, 115, '00:23:18', '00:05:43', '00:00:00', '00:00:00', '00:00:00', '00:00:00', 1); Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted August 5, 2010 Report Share Posted August 5, 2010 (edited) Laikam esmu kkur kko nolaidis grieizi. Neizvadās 'time' jaa taa tiesham irt1.trase1 AS time)+CAST(t1.trase2 AS time)+CAST(t1.trase3 AS time)+CAST(t1.trase4 AS time)+CAST(t1.trase5 AS time)+CAST(t1.trase6 AS time) AS time) AS time Alias cik reizas atkartojas ?? To var izmantot tikai vienu reizi (tas ir vienu nosukumu ), tev pat atkartojas 8 !! reizes Piedevam time ir rezervets vards, labak to neizmantot Edited August 5, 2010 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 5, 2010 Author Report Share Posted August 5, 2010 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'laiks1)+CAST(t1.trase2 AS laiks2)+CAST(t1.trase3 AS laiks3)+CAST(t1.trase4 AS la' at line 1 :/ kādēļ neļauj tādus aliasus? ieliku atpakaļ time, tā uzreiz errors rādas no nākamā alias. SELECT t1.*, CAST(CAST(t1.trase1 AS laiks1)+CAST(t1.trase2 AS laiks2)+CAST(t1.trase3 AS laiks3)+CAST(t1.trase4 AS laiks4)+CAST(t1.trase5 AS laiks5)+CAST(t1.trase6 AS laiks6) AS laiks_laiks) AS trashu_laiks, t2.lietotajvards AS users FROM ".PREFIX."racing_rezultati AS t1, ".PREFIX."lietotaji AS t2 WHERE t1.t_id = '".$tourney['id']."' AND t1.user_id = t2.id AND t1.karta = 1 ORDER BY trashu_laiks ASC Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted August 5, 2010 Report Share Posted August 5, 2010 biskji parsteidzos :( (nogurums .. ) ieksh CAST tieshi janorada datu tips.. nevar izmantot vienkarshi ieksh alias .. tas ir piemeram xx AS time, vai ORDER BY time -- tapec parasti rakstot kverijus visam funkcijam etc,jacenshas izmantot lielie burti , mazie lai paliek nosaukumiem ... Quote Link to comment Share on other sites More sharing options...
marcis Posted August 5, 2010 Report Share Posted August 5, 2010 MySQL tomēr līdz galam nav pārdomājis laika saskaitīšanu :) Risinājums: pārvēršam laiku sekundēs, saskaitam un saskaitītās sekundes pārtaisam atpakaļ uz laiku: mysql> SELECT *, SEC_TO_TIME(TIME_TO_SEC(`trase1`)+TIME_TO_SEC(`trase2`)+TIME_TO_SEC(`trase3`)+TIME_TO_SEC(`trase4`)+TIME_TO_SEC(`trase5`)+TIME_TO_SEC(`trase6`)) AS `total_time` FROM `racing_rezultati`; +----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+ | id | t_id | user_id | trase1 | trase2 | trase3 | trase4 | trase5 | trase6 | karta | total_time | +----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+ | 1 | 523 | 1 | 00:18:15 | 00:05:02 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:23:17 | | 2 | 523 | 147 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 3 | 523 | 349 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 4 | 523 | 145 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 5 | 523 | 159 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 6 | 523 | 198 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 7 | 523 | 405 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:00:00 | | 8 | 523 | 115 | 00:23:18 | 00:05:43 | 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | 1 | 00:29:01 | +----+------+---------+----------+----------+----------+----------+----------+----------+-------+------------+ 8 rows in set (0.00 sec) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.