Pentiums Posted November 21, 2008 Report Share Posted November 21, 2008 Ir tāda lieta: $query = "SELECT * FROM tabulina"; $kverijs = mysql_query($query); while($izvade = mysql_fetch_array($kverijs)){ echo $izvade['name'].", "; } Rezultāti tiek atdalīti ar komatu, bet kā lai izdara lai pēdējam rezultātam komata nebūtu Link to comment Share on other sites More sharing options...
bubu Posted November 21, 2008 Report Share Posted November 21, 2008 Es to parasti daru aptuveni šādi: $delim = ""; while ($item = ...) { echo $delim, $item; $delim = ", "; } Var arī salasīt visus stringus masīvā un tad ar implode fju visus savienot ar ", " atdalītāju. Link to comment Share on other sites More sharing options...
codez Posted November 21, 2008 Report Share Posted November 21, 2008 (edited) $s='';while($izvade = mysql_fetch_array($kverijs)){ $s.=($s==''?'':', '); $s.=$izvade['name']; } echo $s; Edited November 21, 2008 by codez Link to comment Share on other sites More sharing options...
Pentiums Posted November 21, 2008 Author Report Share Posted November 21, 2008 vispār elementāri :)) paldies Link to comment Share on other sites More sharing options...
Zandis Murāns Posted November 21, 2008 Report Share Posted November 21, 2008 $pirmais=true; $query = "SELECT * FROM tabulina"; $kverijs = mysql_query($query); while($izvade = mysql_fetch_array($kverijs)){ echo ($pirmais!=true?',':'').$izvade['name']; $pirmais = false; } Link to comment Share on other sites More sharing options...
xPtv45z Posted November 21, 2008 Report Share Posted November 21, 2008 Es darītu tā.. $query = "SELECT * FROM tabulina"; $kverijs = mysql_query($query); $kautKadsMassivs = array(); while($izvade = mysql_fetch_array($kverijs)){ $kautKadsMassivs[] = $izvade['name']; } if($kautKadsMassivs) echo implode(" ,", $kautKadsMassivs); Link to comment Share on other sites More sharing options...
Mikijs Posted November 21, 2008 Report Share Posted November 21, 2008 Es darītu tā.. $query = "SELECT * FROM tabulina"; $kverijs = mysql_query($query); $kautKadsMassivs = array(); while($izvade = mysql_fetch_array($kverijs)){ $kautKadsMassivs[] = $izvade['name']; } if($kautKadsMassivs) echo implode(" ,", $kautKadsMassivs); kapec tu palaid masivu kautKadsMasivs ja tas tiek palaists uz $izvade ? dari shadi $query = "SELECT * FROM tabulina"; $kverijs = mysql_query($query); for($i=1;$i<=mysql_num_rows($kverijs);$i++) { $izvade = mysql_fetch_array($kverijs); echo $izvade['name']; if($i<mysql_num_rows($kverijs)) echo ", "; } Link to comment Share on other sites More sharing options...
Zandis Murāns Posted November 21, 2008 Report Share Posted November 21, 2008 Jautājums bija par WHILE ciklu. Link to comment Share on other sites More sharing options...
Mikijs Posted November 21, 2008 Report Share Posted November 21, 2008 kada starpbiba vai while vai for ? es personigi pirms uzzinaju par For es lietoju While bet kad uzzinaju par For while nesmu aizitcis. uzskatu ka For atrak strada..:) Link to comment Share on other sites More sharing options...
Delfins Posted November 21, 2008 Report Share Posted November 21, 2008 (edited) if($i<mysql_num_rows($kverijs)) echo ", "; kādēļ tas ir jādara? Vienkāršāk ir: $i = 0; while ( fetch() ) { if ($i != 0) echo ', '; echo 'texts'; $i++; } Edited November 21, 2008 by Delfins Link to comment Share on other sites More sharing options...
xPtv45z Posted November 21, 2008 Report Share Posted November 21, 2008 Piedod, Mikijs. Es 10 reizes izlasīju to ko tu man raksti, bet tā arī nesapratu. Kāpēc tu Atgriezto_ierakstu_skaits*2 reizes skaiti cik ir atgriezti ieraksti? :) Link to comment Share on other sites More sharing options...
Mikijs Posted November 21, 2008 Report Share Posted November 21, 2008 es pac pamaniju ;) tur viss ir ok :D vnk nepamaniju apakshu ;) Link to comment Share on other sites More sharing options...
v3rb0 Posted November 21, 2008 Report Share Posted November 21, 2008 vēl var šitā if(fetch(..)){ echo $row['name']; } while(fetch(..)) { echo ', ' . $row['name']; } Link to comment Share on other sites More sharing options...
andrisp Posted November 21, 2008 Report Share Posted November 21, 2008 Mikijs ar saviem ūberrisinājumiem :>. No offence. Link to comment Share on other sites More sharing options...
Zandis Murāns Posted November 21, 2008 Report Share Posted November 21, 2008 kada starpbiba vai while vai for ?es personigi pirms uzzinaju par For es lietoju While bet kad uzzinaju par For while nesmu aizitcis. uzskatu ka For atrak strada..:) Šitais mega! Link to comment Share on other sites More sharing options...
Recommended Posts