stencilz Posted February 12, 2007 Report Share Posted February 12, 2007 ir datubāze kurā lauks id ar auto_increment vajag izvēlēties rindu kurā col_1 vai col_2 ir $user, bet tā kā šādas rindas var būt vairākas tad rindu ar lielāko id mysql_query("SELECT * FROM tabula WHERE col_1='".$user."' || col_2='".$user."'") kaut kur jāliek MAX(), vai kā man tikt pie tā ko vajag? Link to comment Share on other sites More sharing options...
Roze Posted February 12, 2007 Report Share Posted February 12, 2007 SELECT * FROM tabula WHERE col_1='".$user."' || col_2='".$user." ORDER BY id DESC LIMIT 1 Link to comment Share on other sites More sharing options...
stencilz Posted February 12, 2007 Author Report Share Posted February 12, 2007 (edited) kaut kas nepareizi man te notiek :( izdarīju šādi SELECT COUNT(*) FROM tabula WHERE col_1='".$user."' || col_2='".$user." AND time < DATE_SUB(NOW(), INTERVAL 10 MINUTE) ORDER BY id DESC LIMIT 1 un man atgriež 8 kā tas var būt? mysql_error() arī neko nesaka :( un vispār man atgriež visas tabulas rindu skaitu palīdziet lūdzu kāds :) man ir tabula no kuras vajag izvilkt ārā tabulu kurai laiks nav mazāks nekā pirms 10 minūtēm un jaunāko no tām visām, pirmā kolonna ir id ar auto_increment daru šādi bet nekā: list($count) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM table WHERE user_1='".$id."' || user_2='".$id."' AND time < DATE_SUB(NOW(), INTERVAL 10 MINUTE) ORDER BY id LIMIT 1")) atgriež kopējo rindu skaitu Edited February 22, 2007 by stencilz Link to comment Share on other sites More sharing options...
stencilz Posted February 22, 2007 Author Report Share Posted February 22, 2007 atvainojiet par dubultpostu, bet savādāk laikam netikšu pamanīts Link to comment Share on other sites More sharing options...
Paulinjsh Posted February 22, 2007 Report Share Posted February 22, 2007 SELECT COUNT(*) FROM table WHERE (user_1='".$id."' OR user_2='".$id."') AND time < DATE_SUB(NOW(), INTERVAL 10 MINUTE) ORDER BY id LIMIT 1 Link to comment Share on other sites More sharing options...
Roze Posted February 23, 2007 Report Share Posted February 23, 2007 atvainojiet par dubultpostu, bet savādāk laikam netikšu pamanīts Jopt nu tu jau selectē COUNT(*) kas atgriež skaitli (nevis konkrēto rindu/ierakstu).. proti saskaita visas tās rindas kur izpildās minētais WHERE nosacijums .. Un LIMIT 1 šeit tikai norāda atgriežamo rindu skaitu.. Ja tev vajag konkrētu ierakstu nelieto COUNT(*).. bet gan vienkārši * vai arī tos laukus kurus tev vajag.. proti kā jau rakstīju šis kverijs: SELECT * FROM tabula WHERE (col_1='".$user."' OR col_2='".$user.") AND time < DATE_SUB(NOW(), INTERVAL 10 MINUTE) ORDER BY id DESC LIMIT 1 Link to comment Share on other sites More sharing options...
stencilz Posted February 23, 2007 Author Report Share Posted February 23, 2007 bet ja man vajag tikai rindu skaitu tad nav jēgas selektot visu rindu Link to comment Share on other sites More sharing options...
andrisp Posted February 23, 2007 Report Share Posted February 23, 2007 Cik maz zināms, tad ātrdarbības ziņā COUNT(*) ir tas pats, kas COUNT(lauks). Link to comment Share on other sites More sharing options...
v3rb0 Posted February 23, 2007 Report Share Posted February 23, 2007 ja apskatam mysql un myisam tabulas, tad count(*) ir ātrāks par count(lauks), bez gūglēšanas nezinu, kā ir, ja 'lauks' ir indexēts, vai pat primārā atslēga. Link to comment Share on other sites More sharing options...
stencilz Posted February 23, 2007 Author Report Share Posted February 23, 2007 (edited) esmu negudrs :) visu sapratu > zīme bija nepareizi Edited February 23, 2007 by stencilz Link to comment Share on other sites More sharing options...
Recommended Posts