Jump to content
php.lv forumi

Kaapeec neatteelo peed 5 ieraxtus??


Uldeens

Recommended Posts

<? // 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 by Uldeens
Link to comment
Share on other sites

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 by bubu
Link to comment
Share on other sites

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

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

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

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

×
×
  • Create New...