Jump to content
php.lv forumi

MySQL datu sadaliishana vairaakaas lapaas


Klokjis

Recommended Posts

nu page=... dalaas ok. bet veel 1 jautaajums... negribeejaas speciaali jaunu topic taisiit... kjipa:

 

<?
$krasa1 = 'FFE7CF';
$krasa2 = 'FFB66E';
$skaits = 0; 

$krasa = ($skaits % 2) ? $krasa1 : $krasa2; 

...

while ($row = mysql_fetch_assoc($result)) { 
echo "\t\t\t<tr bgcolor='".$krasa."'>"; 
echo "<td width='30' align='center' class='krtabula'></td>"; 
echo "<td width='75' class='tabula'> ".$row[$vards]."</td>"; 
echo "<td width='75' class='tabula'> ".$row[$uzvards]."</td>";
...
echo "</tr>\n"; 
} 

$skaits++;  
?>

 

kur te ir kljuuda, deelj kuras $krasa2 neiekraasojas, katrs 2. <tr>, bet gan visi...???

Link to comment
Share on other sites

Izlasi savu kodu pats:

<?
$krasa1 = 'FFE7CF'; // piešķiram $krasa1 kautkādu konstanti.
$krasa2 = 'FFB66E'; // piešķiram $krasa2 kautkādu citu konstanti.
$skaits = 0; // piešķiram $skaits vērtibu 0

$krasa = ($skaits % 2) ? $krasa1 : $krasa2; // tā kā $skaits=0, un 0%2=0=false, tad $krasa piešķiram $krasa2 

...

while ($row = mysql_fetch_assoc($result)) { // kautko daram ciklā ($krasa nemainās!)
echo "\t\t\t<tr bgcolor='".$krasa."'>";
echo "<td width='30' align='center' class='krtabula'></td>";
echo "<td width='75' class='tabula'>&nbsp".$row[$vards]."</td>";
echo "<td width='75' class='tabula'>&nbsp".$row[$uzvards]."</td>";
...
echo "</tr>\n";
} // cikls beidzās

$skaits++;   // palielinam $skaits par 1, tātad 0+1=1=$skaits
?>

 

Es piem neredzu vietu, kur $krasa mainīgajam būtu pie katras rindas ciklā jāmainās...

Link to comment
Share on other sites

<?
$krasa1 = 'FFE7CF';
$krasa2 = 'FFB66E';

...

$i = 1;
while ($row = mysql_fetch_assoc($result)) {
$krasa = ($i % 2) ? $krasa1 : $krasa2;
echo "\t\t\t<tr bgcolor='".$krasa."'>";
echo "<td width='30' align='center' class='krtabula'></td>";
echo "<td width='75' class='tabula'> ".$row[$vards]."</td>";
echo "<td width='75' class='tabula'> ".$row[$uzvards]."</td>";
...
echo "</tr>\n";
$i++;
}

?>

Edited by Robis
Link to comment
Share on other sites

×
×
  • Create New...