atari Posted July 5, 2005 Report Share Posted July 5, 2005 Saakshu ar to, kad datubaazees esmu iesaaceejs, jautaajums taads: kaa var summeet laukus, kas atrodas mysql datubaazes tabulaa. Tabulaa ir lauks 'total_filesize' - viena faila izmeers, veelos lai vareetu saitaa redzeet visu failu kopeejo izmeeru. kaada php funkcija ir jaaraksta? Paldies! Link to comment Share on other sites More sharing options...
bubu Posted July 5, 2005 Report Share Posted July 5, 2005 Vai http://dev.mysql.com/ nav jāatver? SELECT SUM(total_filesize) FROM tabula Link to comment Share on other sites More sharing options...
atari Posted July 5, 2005 Author Report Share Posted July 5, 2005 Uzrakstiet, ja nav gruuti, kaa to visu var dabuut uz "ekraana"? Visu funkciju. Teiksim datubaazee ir lauks user_name un file_name, es veelos, lai katrs lietotaajs vareetu redzeet savu kopeejo izmantoto apjomu un failu skaitu. Paldies! Link to comment Share on other sites More sharing options...
des Posted July 5, 2005 Report Share Posted July 5, 2005 (edited) Uzrakstiet, ja nav gruuti, kaa to visu var dabuut uz "ekraana"? Visu funkciju.Teiksim datubaazee ir lauks user_name un file_name, es veelos, lai katrs lietotaajs vareetu redzeet savu kopeejo izmantoto apjomu un failu skaitu. Paldies! 19047[/snapback] nu tipa taa (pac primitiivaakais variants)? $r = mysql_query('select count(file_name) as skaic from tabula where user_name=\''.$username.'\''); $l = mysql_fetch_assoc($r); echo $l['skaits']; $r = mysql_query('select sum(total_filesize) as apjoms from tabula where user_name=\''.$username.'\''); $l = mysql_fetch_assoc($r); echo $l['apjoms']; Edited July 6, 2005 by des Link to comment Share on other sites More sharing options...
Venom Posted July 6, 2005 Report Share Posted July 6, 2005 SQL kvērijiem vieglāk izmantot ": "SELECT COUNT(file_name) AS skaits FROM tabula WHERE user_name='".$username."'" Link to comment Share on other sites More sharing options...
des Posted July 6, 2005 Report Share Posted July 6, 2005 SQL kvērijiem vieglāk izmantot ":"SELECT COUNT(file_name) AS skaits FROM tabula WHERE user_name='".$username."'" 19058[/snapback] Nu laikam jau, ka tiiri vizuaali cilveekam shitais ir vieglaak uztverams. Tie backslashi reizeem jauc galvu. It seviskji situaacijaas, kad vinji ir vajadziigi triis peec kaartas. Link to comment Share on other sites More sharing options...
Venom Posted July 6, 2005 Report Share Posted July 6, 2005 + esmu pieradis tabulu nosaukumus likt mainīgos: "SELECT COUNT(file_name) AS skaits FROM $tFiles WHERE user_name='".$username."'" etc Link to comment Share on other sites More sharing options...
des Posted July 6, 2005 Report Share Posted July 6, 2005 + esmu pieradis tabulu nosaukumus likt mainīgos:"SELECT COUNT(file_name) AS skaits FROM $tFiles WHERE user_name='".$username."'" etc 19060[/snapback] Nu tipa jau vispaar 'strings '.$mainiigais.' strings' parseejaas aatraak nekaa "strings $mainiigais strings" Link to comment Share on other sites More sharing options...
Venom Posted July 6, 2005 Report Share Posted July 6, 2005 tā arī tiek darīts, bet reizēm arī atstāts, ja kvērijs ir pagarāks, e.g. "SELECT $tA.title as `area`, $tC.number FROM $tC LEFT JOIN $tA ON $tC.area=$tA.aID ORDER BY $tA.title, $tC.number" tomēr lasās labāk, nekā kad visur būtu "...".$tTable.".column ..." Link to comment Share on other sites More sharing options...
des Posted July 6, 2005 Report Share Posted July 6, 2005 a kaadas probleemas ir rakstiit shitaa, ievieshot tabulaam aliasus (parasti ne garaakus kaa 3 simb, bet taadus, kas viegli asocieejas ar pilno tabulas nosaukumu): 'SELECT ta.title as `area`, tc.number FROM '.$tC.' as tc LEFT JOIN '.$tA.' as ta ON tc.area=ta.aID ORDER BY ta.title, tc.number' Shajaa gadiijumaa arii, ja tiek joinotas vairaak kaa 2 tabulas, katrs tabulas mainiitais tiek referenceets tikai vienu reizi. Link to comment Share on other sites More sharing options...
Venom Posted July 6, 2005 Report Share Posted July 6, 2005 tā jau jāaceras mainīgais, tad vēl aliass, un vienu reizi aliass prātā ienāks šāds, vēlāk citāds, nu tā, KISS princips Link to comment Share on other sites More sharing options...
Kaklz Posted July 6, 2005 Report Share Posted July 6, 2005 nu tā, KISS princips 19068[/snapback] KISS būtu tad, ja tu neizmantotu tabulas nosaukumam mainīgo. Tiešām neredzu iemeslu, kāpēc 99.9% gadījumu tas būtu vajadzīgs. Link to comment Share on other sites More sharing options...
Venom Posted July 6, 2005 Report Share Posted July 6, 2005 a man bieži nākas turēt vairākas sys vienā db. tāpē laiku pa laikam rodas nepieciešamība mainīt tabulu nosaukumus vai vismaz likt priekšā prefixus Link to comment Share on other sites More sharing options...
Recommended Posts