Uldeens Posted August 22, 2004 Report Share Posted August 22, 2004 (edited) <? // connect to mysql database mysql_connect("www.freesql.org", "zzz","xxx"); // select database mysql_select_db("yyy"); $sqlMess="select nick from HVZ order by desc limit 5"; $result=mysql_query($sqlMess) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) $nick[$i]=$row[$i]; for($i=0;$<5;$i++) echo $nick[$i] <br>; } mysql_close(); ?> parse error, expecting `T_VARIABLE' or `''' PS Vienu ieraxtu man izdevaas izvadiit for cikla vietaa izmantojot echo $nick Edited August 22, 2004 by Uldeens Link to comment Share on other sites More sharing options...
bubu Posted August 22, 2004 Report Share Posted August 22, 2004 (edited) Kad savu kodu te liec, tad liec to [ code ] un [ /code ] tagos! Šādi: <? // connect to mysql database mysql_connect("www.freesql.org", "zzz","xxx"); // select database mysql_select_db("yyy"); $sqlMess="select nick from HVZ order by desc limit 5"; $result=mysql_query($sqlMess) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) $nick[$i]=$row[$i]; for($i=0;$<5;$i++) echo $nick[$i] <br>; } mysql_close(); ?> Tagad par tavām kļūdām: 1) $nick[$i]=$row[$i]; - A cik šinī vietā ir $i ? Neesi padomājis par to? 2) echo $nick[$i] <br>; Negribi stringu ielikt pēdiņās, tb echo $nick[$i].'<br>'; 3) while cikla ķermeni iesaku ielikt { } simbolos, šādi: while ($row = mysql_fetch_array($result)) { $nick[$i]=$row[$i]; } 4) Un ja jau gribi izvadīt visus piecus nikus (pie tam, tev netiek garantēts, ka būs precīzi 5 niki, var jau būt ka selekts atgriež mazāk ierakstu), tad daries šādi: while ($row = mysql_fetch_array($result)) { echo $row[0].'<br />'; } Edited August 22, 2004 by bubu Link to comment Share on other sites More sharing options...
Uldeens Posted August 22, 2004 Author Report Share Posted August 22, 2004 Blaaviens man nepaliidzeeja.. Googlee arii ir piemeeri nepaliidz tur ir vai nu pirmaa atlasiisanas dala vai izvadiisanas a man neiet.Vajag visu skriptu:))) Jau gadu 4akareejos un neesu iemaacijies izvadiit datus.Nu vienu rindu jaa bet vairaak...SECINASAJUMS nemaaku straadaat ar masiiviem un tiem cikliem for,foreach utt.. Link to comment Share on other sites More sharing options...
Uldeens Posted August 22, 2004 Author Report Share Posted August 22, 2004 Viss teema aizveerta..Atradu risinaajumu. <? // connect to mysql database mysql_connect("www.freesql.org", "xxx","xxx"); // select database mysql_select_db("qw"); //inserting data $sqlMess="select nick,msg from nnn order by id desc"; $result=mysql_query($sqlMess) or die(mysql_error()); $number = MYSQL_NUMROWS($result); if ($number > 0) { $i = 0; while ($i < 5){ $nickname1 = mysql_result($result,$i,"nick"); $msg1 = mysql_result($result,$i,"msg"); echo "<b>$nickname1</b>";echo ":"; echo $msg1;echo"<br/>"; $i++; } } ?> Link to comment Share on other sites More sharing options...
bubu Posted August 23, 2004 Report Share Posted August 23, 2004 Tas nav labs risinājumjs, jo tu atlasi pilnīgi visus ierakstus, kas var būt ir ļoooti daudz, bet izmanto tikai 5 no tiem, tādējādi bezjēdzīgi noslogojot serveri. Link to comment Share on other sites More sharing options...
Uldeens Posted August 23, 2004 Author Report Share Posted August 23, 2004 A kaa man dariit??Ielikt aiz selecta LIMIT 10??vai 5?? Link to comment Share on other sites More sharing options...
Gacha Posted August 23, 2004 Report Share Posted August 23, 2004 Es nez ko tu tur peries, bet tas viss ir pavisam vienkārši: $sql = mysql_query("Select * from table order by id desc Limit 0, 5"); while($row = mysql_fetch_assoc($sql)){ echo $row['data1'].'<br />'; echo $row['data2'].'<br />'; echo $row['data3'].'<br />'; echo $row['data4'].'<br />'; } Kas te nesaprotams? Tas kods ko tu tur ieliki bija pa garu un pa sarežģītu ! Link to comment Share on other sites More sharing options...
bubu Posted August 23, 2004 Report Share Posted August 23, 2004 Tak manu 4 punktu apskaties un ieliec to tā kā arī Gacha rāda: <? mysql_connect('www.freesql.org', 'zzz','xxx'); mysql_select_db('yyy'); $sqlMess='select nick from HVZ order by desc limit 5'; $result=mysql_query($sqlMess) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { echo $row[0] . '<br />'; } } mysql_close(); ?> Link to comment Share on other sites More sharing options...
Recommended Posts