Cevaplar
-
Soruyu değiştirerek anlaşılır halde tekrar soruyorum
yukarıda verdiğim örneği unutun şimdi anlatacaklarım üzerinden düşünelim
php ile while döngüsü kullanarak veritabanındaki kullanicilar isimli tablomdaki tüm verileri tabloya çekmek istiyorum
kullanıcılar isimli tablomda id,adi,soyadi,telefon isimli sutunlar var
tablo başlıkları yukarıda verdiğim gibi olacak
tabloya çektiğim veriler ise bir satır kırmızı diğer satır beyaz olacak sonraki yine kırmızı yine beyaz bu şekilde while içinde döndükçe veri çekecek veriyi her çektiğinde tablo'nun zemin rengi bu iki renk arasında değişecek bunu nasıl yaparım -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/stil.css" rel="stylesheet" type="text/css" /></head>
<body>
<?
$renk1 = "<?=$bgcolor;?>";
$renk2 = "#ffffcc";
?>
<table width="100%" border="0" cellpadding="2">
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" >
<tr>
<td width="40" bgcolor="#F54425"><span class="id"><strong>ID</strong></span></td>
<td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>RM</strong></span></td>
<td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>KM</strong></span></td>
<td width="24" align="center" bgcolor="#F54425"><span class="id"><strong>HB</strong></span></td>
<td width="23" align="center" bgcolor="#F54425"><span class="id"><strong>SD</strong></span></td>
<td width="25" align="center" bgcolor="#F54425"><span class="id"><strong>ÖH</strong></span></td>
<td width="300" height="20" valign="middle" bgcolor="#F54425"><span class="id"><strong>Kategori</strong></span></td>
<td width="500" bgcolor="#F54425"><span class="id"><strong>Başlık</strong></span></td>
<td width="39" bgcolor="#F54425"> <span class="id"><strong>Hit </strong></span></td>
<td width="150" bgcolor="#F54425"><span class="id"><strong> Editör </strong></span></td>
<td width="120" bgcolor="#F54425"><span class="id"><strong> Eklenme Tarihi </strong></span></td>
<th width="70" bgcolor="#F54425"><span class="id"><strong> İşlem </strong></span></th>
<th width="10" bgcolor="#F54425">
<span class="id">
<label>
<input type="checkbox" name="checkbox" id="checkbox" />
</label>
</span></th>
</tr>
<?
$i=0;
while($row=mysql_fetch_array($sql)) {
if($i%2) { # Eger i degiskeni çifter giderse istedigimiz döngüyü kuruyoruz.
$bgcolor = $renk1;
} else {
$bgcolor = $renk2;
}
?>
<tr>
<td bgcolor="<?=$bgcolor;?>" class="id">14151</td>
<td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td>
<td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td>
<td bgcolor="<?=$bgcolor;?>"><img src="img/hayir.png" width="20" height="20" /></td>
<td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td>
<td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td>
<td bgcolor="<?=$bgcolor;?>" class="id">DÜNYA</td>
<td bgcolor="<?=$bgcolor;?>"><span class="id"><strong>1.6 KM' lik Dünyanın En Uzun Binası Yapılıyor...</strong></span></td>
<td bgcolor="<?=$bgcolor;?>"><span class="id"><strong>18684</strong></span></td>
<td bgcolor="<?=$bgcolor;?>" class="id">Mustafa YILDIZ</td>
<td bgcolor="<?=$bgcolor;?>"><span class="id"><strong>30.12.2011 21.30.58</strong></span></td>
<td bgcolor="#FFFFFF">
<table width="100%">
<tr bgcolor="<?=$bgcolor;?>" class="id">
<td width="20" nowrap="nowrap" class="kutu"><img src="img/duzenle.png" width="20" height="20" /></td>
<td width="20" nowrap="nowrap" class="kutu"><img src="img/onizle.png" width="20" height="20" /></td>
<td width="20" nowrap="nowrap" class="kutu"><img src="img/aktif.png" width="20" height="20" /></td>
<td width="20" nowrap="nowrap" class="kutu"><img src="img/sil.png" width="20" height="20" /></td>
<td width="70" align="center" nowrap="nowrap" class="islem_durum">Onaylanmadı</td>
</tr>
</table></td>
<td bgcolor="<?=$bgcolor;?>" class="id"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
</tr>
<?
$i++;
} // while bitisi ?>
</table>
<p class="id"> </p>
</body>-
muttoli
hocam while içinde while oluyor o zaman kafam karıştı ben sana örnek kodları yollasam da bi baksan
sen sadece renk değiştiren kodu yollamışsın bana yolladığın koda birde veri çekecek kodu da yazarsan yada aşağıdaki kodu düzeltirsen çok sevinirim
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/stil.css" rel="stylesheet" type="text/css" /></head> <body> <? $renk1 = "#fff000"; $renk2 = "#ffffcc"; ?> <table width="100%" border="0" cellpadding="2"> <tr> <td bgcolor="#FFFFFF"><table width="100%" border="0" > <tr> <td width="40" bgcolor="#F54425"><span class="id"><strong>ID</strong></span></td> <td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>RM</strong></span></td> <td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>KM</strong></span></td> <td width="24" align="center" bgcolor="#F54425"><span class="id"><strong>HB</strong></span></td> <td width="23" align="center" bgcolor="#F54425"><span class="id"><strong>SD</strong></span></td> <td width="25" align="center" bgcolor="#F54425"><span class="id"><strong>ÖH</strong></span></td> <td width="300" height="20" valign="middle" bgcolor="#F54425"><span class="id"><strong>Kategori</strong></span></td> <td width="500" bgcolor="#F54425"><span class="id"><strong>Başlık</strong></span></td> <td width="39" bgcolor="#F54425"> <span class="id"><strong>Hit </strong></span></td> <td width="150" bgcolor="#F54425"><span class="id"><strong> Editör </strong></span></td> <td width="120" bgcolor="#F54425"><span class="id"><strong> Eklenme Tarihi </strong></span></td> <th width="70" bgcolor="#F54425"><span class="id"><strong> İşlem </strong></span></th> <th width="10" bgcolor="#F54425"> <span class="id"> <label> <input type="checkbox" name="checkbox" id="checkbox" /> </label> </span></th> </tr> <tr> <td bgcolor="#EAEAEA" class="id"><? require_once("ayar.php"); $sorgu = mysql_query("select * from haberler"); while ($islem = mysql_fetch_array($sorgu)) { while($row=mysql_fetch_array($sql)) { if($i%2) { # Eger i degiskeni çifter giderse istedigimiz döngüyü kuruyoruz. $bgcolor = $renk1; } else { $bgcolor = $renk2; } echo "{$islem['id']}";?><br></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/hayir.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>" class="id"><? echo "{$islem['h_haber_kategori']}";?></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_baslik']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_hit']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>" class="id"><? echo "{$islem['h_haber_editor']}";?></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_tarih']}--{$islem['h_haber_saat']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>"><table width="100%"> <tr bgcolor="<?=$bgcolor;?>" class="id"> <td width="20" nowrap="nowrap" class="kutu"><img src="img/duzenle.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/onizle.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/aktif.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/sil.png" width="20" height="20" /></td> <td width="70" align="center" nowrap="nowrap" class="islem_durum">Onaylanmadı</td> </tr> </table></td> <td bgcolor="#EAEAEA" class="id"><input type="checkbox" name="checkbox2" id="checkbox2" /></td> </tr> </table></td> </tr> <? } } // while bitisi ?> </table> <p class="id"> </p> </body> </html>
11 yıl önce yazılmış -
siyahbeyaz
while($row=mysql_fetch_array($sql)) { şu satırı silin..
$i=0; while nın ustune ekleyin.
en sondaki
}} // while bitisini
$i++;
} //while bitisi seklinde getirin..11 yıl önce yazılmış -
siyahbeyaz
yani kod bu sekilde olacak
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/stil.css" rel="stylesheet" type="text/css" /></head> <body> <? $renk1 = "#fff000"; $renk2 = "#ffffcc"; ?> <table width="100%" border="0" cellpadding="2"> <tr> <td bgcolor="#FFFFFF"><table width="100%" border="0" > <tr> <td width="40" bgcolor="#F54425"><span class="id"><strong>ID</strong></span></td> <td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>RM</strong></span></td> <td width="28" align="center" bgcolor="#F54425"><span class="id"><strong>KM</strong></span></td> <td width="24" align="center" bgcolor="#F54425"><span class="id"><strong>HB</strong></span></td> <td width="23" align="center" bgcolor="#F54425"><span class="id"><strong>SD</strong></span></td> <td width="25" align="center" bgcolor="#F54425"><span class="id"><strong>ÖH</strong></span></td> <td width="300" height="20" valign="middle" bgcolor="#F54425"><span class="id"><strong>Kategori</strong></span></td> <td width="500" bgcolor="#F54425"><span class="id"><strong>Başlık</strong></span></td> <td width="39" bgcolor="#F54425"> <span class="id"><strong>Hit </strong></span></td> <td width="150" bgcolor="#F54425"><span class="id"><strong> Editör </strong></span></td> <td width="120" bgcolor="#F54425"><span class="id"><strong> Eklenme Tarihi </strong></span></td> <th width="70" bgcolor="#F54425"><span class="id"><strong> İşlem </strong></span></th> <th width="10" bgcolor="#F54425"> <span class="id"> <label> <input type="checkbox" name="checkbox" id="checkbox" /> </label> </span></th> </tr> <tr> <td bgcolor="#EAEAEA" class="id"><? require_once("ayar.php"); $i=0; $sorgu = mysql_query("select * from haberler"); while ($islem = mysql_fetch_array($sorgu)) { if($i%2) { # Eger i degiskeni çifter giderse istedigimiz döngüyü kuruyoruz. $bgcolor = $renk1; } else { $bgcolor = $renk2; } echo "{$islem['id']}";?><br></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/hayir.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>"><img src="img/evet.png" width="20" height="20" /></td> <td bgcolor="<?=$bgcolor;?>" class="id"><? echo "{$islem['h_haber_kategori']}";?></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_baslik']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_hit']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>" class="id"><? echo "{$islem['h_haber_editor']}";?></td> <td bgcolor="<?=$bgcolor;?>"><span class="id"><strong><? echo "{$islem['h_haber_tarih']}--{$islem['h_haber_saat']}";?></strong></span></td> <td bgcolor="<?=$bgcolor;?>"><table width="100%"> <tr bgcolor="<?=$bgcolor;?>" class="id"> <td width="20" nowrap="nowrap" class="kutu"><img src="img/duzenle.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/onizle.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/aktif.png" width="20" height="20" /></td> <td width="20" nowrap="nowrap" class="kutu"><img src="img/sil.png" width="20" height="20" /></td> <td width="70" align="center" nowrap="nowrap" class="islem_durum">Onaylanmadı</td> </tr> </table></td> <td bgcolor="#EAEAEA" class="id"><input type="checkbox" name="checkbox2" id="checkbox2" /></td> </tr> </table></td> </tr> <? $i++; } // while bitisi ?> </table> <p class="id"> </p> </body> </html>
11 yıl önce yazılmış -
muttoli
hocam renk olayı tamam ama satır kayıyor sanırım while bitişinde sorun var11 yıl önce yazılmış -
css97
<?php $a = "1"; $renk=array("#CCCCCC","#FFFFCC"); $renkindex=0; print "<table border=1>"; while($a<10){ print "<tr bgcolor=".$renk[$renkindex].">"; print "<td width=40>".$a++."</td>"; print "</tr>"; $renkindex = 1-$renkindex; } print "</table>"; ?>
while döngüsünü yazıp kullanabilirsin.11 yıl önce yazılmış -
siyahbeyaz
hocam html bilginiz az sanırım...
<tr>
<td bgcolor="#EAEAEA" class="id"><? require_once("ayar.php");
$i=0;
$sorgu = mysql_query("select * from haberler");
while ($islem = mysql_fetch_array($sorgu))
{
kısmını
<td bgcolor="#EAEAEA" class="id"><? require_once("ayar.php");
$i=0;
$sorgu = mysql_query("select * from haberler");
while ($islem = mysql_fetch_array($sorgu))
{
echo '<tr>';
olarak degistir11 yıl önce yazılmış -
muttoli
("hocam html bilginiz az sanırım... ")
Bu da ne demek yani ???
Hocam html bilgim iyi konu o değil di
while içinde while kullanılınca kafam karıştı zaten orayı da düzelttim sonra dan
ben çözdüm olayı yinede teşekkürler11 yıl önce yazılmış
-