torrentz Posted October 12, 2007 Report Share Posted October 12, 2007 Pirmaa tabula: CREATE TABLE `category` ( `uid` INT(16), `category` enum('0','1','2','3','4','5','6','7','8','9','10') NOT NULL default '0', PRIMARY KEY ( `uid` ) ) TYPE=MyISAM COMMENT='kategorijas'; Otraa tabula: CREATE TABLE `weeks` ( `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL default '0', `next_mon` int(10) unsigned NOT NULL default '0', `date` int(10) unsigned NOT NULL default '0', `day_week` smallint(5) unsigned NOT NULL default '0', `count` int(10) unsigned NOT NULL default '0', `host` int(10) unsigned NOT NULL default '0', `in` int(10) unsigned NOT NULL default '0', `out` int(10) unsigned NOT NULL default '0', `Siemens` int(10) unsigned NOT NULL default '0', `Nokia` int(10) unsigned NOT NULL default '0', `Samsung` int(10) unsigned NOT NULL default '0', `Motorola` int(10) unsigned NOT NULL default '0', `LG` int(10) unsigned NOT NULL default '0', `Sagem` int(10) unsigned NOT NULL default '0', `SonyEricsson` int(10) unsigned NOT NULL default '0', `Alcatel` int(10) unsigned NOT NULL default '0', `Opera` int(10) unsigned NOT NULL default '0', `Mozilla` int(10) unsigned NOT NULL default '0', `Panasonic` int(10) unsigned NOT NULL default '0', `Other` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=16336 ; Koda gabals: $result = mysql_query("SELECT count(`uid`) FROM `weeks` WHERE `host` > 0 and `date`=$today"); $cntData = mysql_fetch_row($result); $count_users = $cntData[0]; $result=mysql_query("SELECT DISTINCT uid,count,host FROM weeks WHERE host > 0 AND date=$today ORDER BY host DESC LIMIT $start,$end"); $count_users_on_page = mysql_num_rows($result); Kaa man paarveidot vaicaajumus, lai php skripts neizveeleetos visus UID, bet gan tikai tos UID, kas ir, piemeeram, kategorijā 5? Pilns skipta kods: http://paste.php.lv/6232 Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 Es nezinu, vai tas būs optimālākais kverijs, bet: SELECT count(`uid`) FROM `weeks` LEFT JOIN kat ON ( weeks.uid = kat.uid ) WHERE `host` > 0 and `date`=$today AND kat.category = 5 Link to comment Share on other sites More sharing options...
torrentz Posted October 12, 2007 Author Report Share Posted October 12, 2007 Ir tāda lieta, ka $result = mysql_query("SELECT count(`uid`) FROM `weeks` LEFT JOIN kat ON ( weeks.uid = kat.uid ) WHERE `host` > 0 and `date`=$today AND kat.category = 0"); $cntData = mysql_fetch_row($result); $count_users = $cntData[0]; tas count_users paraada neko un pie tam uzmet taadu erroru: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/wapcount/public_html/portal.php on line 132 visiem UID ieksh category tabulas, kategorija pagaidaam ir 0, taatad buutu jaaizvada cipars kaut kur ap ~140 Kaa ir japārveido ši vaicājums, lai vinjsh izveeleetos tikai noteiktu kategorijas UID? $result=mysql_query("SELECT DISTINCT uid,count,host FROM weeks WHERE host > 0 AND date=$today ORDER BY host DESC LIMIT $start,$end"); $count_users_on_page = mysql_num_rows($result); Un vai šis vaicajums vispār ir jāpārveido (tas izvada tikai pirmos piecs UID vienaa lapaa)? Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 Klau, tas kods, ko es iemetu bija ar neīstu tabulas nosaukumu ? Tu pirms kopē kaut kur kodu, nepārbaudi, ko viņš dara ? Link to comment Share on other sites More sharing options...
xPtv45z Posted October 12, 2007 Report Share Posted October 12, 2007 Vai tad lai COUNT strādātu nav nepieciešams arī GROUP BY? Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 Nē. Link to comment Share on other sites More sharing options...
torrentz Posted October 12, 2007 Author Report Share Posted October 12, 2007 (edited) Tur jau tā lieta, ka tiešām es neko nejeedzu vairaak par update table set a=$b where uid=$uid :) kat bija jaanomaina uz category? taa ir pareizi? veeljoprojaam nestraadaa un count_USERS NEKO NERAADA $result = mysql_query("SELECT count(`uid`) FROM `weeks` LEFT JOIN category ON ( weeks.uid = category.uid ) WHERE `host` > 0 and `date`=$today AND category.category = 0"); $cntData = mysql_fetch_row($result); $count_users = $cntData[0]; Edited October 12, 2007 by torrentz Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 protams. Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 AND category.category = 0 to nullīti liec iekš pēdiņām. Kāpēc ? http://laacz.lv/2006/05/08/mysql-gotcha/ Link to comment Share on other sites More sharing options...
torrentz Posted October 12, 2007 Author Report Share Posted October 12, 2007 neesmu ielicis peedinjas vnk tas viss ir ieksh $result = mysql_query(""); cik izlasiiju no tava bloga, tad man taas peedinjas tomeer ir jaaliek? Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 No mana bloga ? Un kāds tam sakars ar mysql_query() ? Pēdiņās jāliek tā nullīte pie category.category = 0. Tas nozīmē, kas es domāju šādi: category.category = '0' Un kāpēc tā jādara, vari izlasīt iekš laacz.lv bloga. Un ja tu domāji, ka tas ir mans blogs, tad tu maldies. :) Link to comment Share on other sites More sharing options...
torrentz Posted October 12, 2007 Author Report Share Posted October 12, 2007 (edited) ups, sajaucu apblog ar laacz :D shitaa ir pareizi? $result = mysql_query("SELECT count(`uid`) FROM `weeks` LEFT JOIN category ON ( weeks.uid = category.uid ) WHERE `host` > 0 and `date`=$today AND category.category = '0'"); $cntData = mysql_fetch_row($result); $count_users = $cntData[0]; Edited October 12, 2007 by torrentz Link to comment Share on other sites More sharing options...
andrisp Posted October 12, 2007 Report Share Posted October 12, 2007 A tu pamēģini. Bet nu manām acīm izskatās, ka viss ok. Link to comment Share on other sites More sharing options...
torrentz Posted October 12, 2007 Author Report Share Posted October 12, 2007 (edited) Nestraadaa, veeljoprojaam $result = mysql_query("SELECT count(`uid`) FROM `weeks` LEFT JOIN category ON ( weeks.uid = category.uid ) WHERE `host` > 0 and `date`=$today AND category.category = '0'"); $cntData = mysql_fetch_row($result); $count_users = $cntData[0] izvada shito: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/wapcount/public_html/portal.php on line 133 lai gan category tabulaa visiem UID no 1 liidz 3000 kategorija ir 0... Varbuut probleema ir tajaa, ka weeks tabulaa ir mazaak UID nekaa categoy tabulaa (tur es saliku vairaak UID priekshdienaam...)? Edited October 12, 2007 by torrentz Link to comment Share on other sites More sharing options...
Vebers Posted October 12, 2007 Report Share Posted October 12, 2007 Vienigā problēma var būt $today mainīgajā, neizskatījās, ka viņš k-kur tiktu definēts. Ja pareizi sapratu ko vēlies panākt vari iemēģināt šito : SELECT count(*) as cnt, w.uid, w.count, w.host FROM weeks w, category c WHERE w.host > 0 AND w.date=$today and c.category = '5' GROUP BY uid ORDER BY w.host DESC Link to comment Share on other sites More sharing options...
Recommended Posts