Autor Zpráva
pan šikovný
Profil *
ahoj, všici jak se dají obarvit řádky při výpisu z databáze? Já zkoušel něco vytvořit ale je tam někde chyba a nejde to


<style type='text/css'>

.suda { background-color: #CCCCCC; }
.licha { background-color: yellow; }
</style>
<?php
function ObarvitRadek($suda="suda",$licha="licha",$obarvit=""){
$obarvit=($obarvit==$suda) ? $licha : $suda;
return $obarvit;
}

?>

<?

require_once "../include/connect.php"; //otevřeme databázi
$vysledek = MySQL_Query("select * from tabulka where test='tag'"); //or die('Nastala chyba')
echo mysql_error();

while ($zaznam=MySQL_Fetch_Array($vysledek))
{

$obarvit=ObarvitRadek("suda","licha",$obarvit);
echo'<table border="0" width="100%">
<tr class="'.$obarvit.'">
<td width="25%">'.$zaznam["nazev"].'</td>
<td width="25%">&nbsp;</td>
<td width="25%"></td>
<td width="25%">&nbsp;</td>
</tr>
</table>';
};?>
Alphard
Profil
$i = 1;
while ($zaznam=MySQL_Fetch_Array($vysledek))
{

echo'<table border="0" width="100%">
<tr class="';
if ($i%2 == 1) echo "licha"; else echo "suda";
echo '"<td width="25%">'.$zaznam["nazev"].'</td>
<td width="25%">&nbsp;</td>
<td width="25%"></td>
<td width="25%">&nbsp;</td>
</tr>
</table>';
$i++;
};?>
krteczek_jinde
Profil *
je tam drobná chyba, skládáš to z tolika tabulek kolik mášřádků v databázi. to asi nechceš.

$text = '<table>';
$i = 1;
while ($zaznam=MySQL_Fetch_Array($vysledek))
{
$text .= "\n" . '<tr class="' . ($i%2 == 1 ? "licha" : "suda") . '!>';
$text .= '<td width="25%">' . $zaznam["nazev"] . '</td>';
$text .= '<td width="25%">&nbsp;</td>';
$text .= '<td width="25%"></td>';
$text .= '<td width="25%">&nbsp;</td>';
$text .= '</tr> ';
}
$text .= "\n</table>';
echo $text;

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0