Oleh: Hamba Allah | Agustus 4, 2009

Menampilkan baris beda warna pada tabel

<?
include “config.php”;
$tampil=mysql_query(“select * from data_penulis”);
while($baris=mysql_fetch_array($tampil)){
$no++;
?>
<tr bgcolor=”
<?
if($no%2==1) {
echo”red”; //apabila variable nomor ganjil maka barisnya warna merah
}
else {
echo”yellow”; //apabila variable nomor genap maka barisnya warna kuning
}
?>
//menampilkan data per baris
“>

Implementasi di Dreamweaver :
Jika menggunakan repeat region di DW maka kode diatas bisa dicustom sbb :

<?
….
$maxRows_rs_tabel = 20;
$pageNum_rs_tabel = 0;
if (isset($_GET['pageNum_rs_tabel'])) {
$pageNum_rs_tabel = $_GET['pageNum_rs_tabel'];
}
$startRow_rs_tabel = $pageNum_rs_tabel * $maxRows_rs_tabel;
….
?>

<?php do {  ?>
<?  $startRow_rs_tabel++; ?>
<tr  bgcolor=”<?php if ($startRow_rs_tabel%2==1) {echo “red”; } else {echo “yellow”;} ?>”>
<td>
</td>
</tr>
<?php } while ($row_rs_tabel = mysql_fetch_assoc($rs_tabel))
?>

Semoga bermanfaat !


Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s

Kategori

Ikuti

Get every new post delivered to your Inbox.