Buraya sql üzerinden veri çekmekteyim. Görüntü olarak örneğin bir satır gri bir satır beyaz gelmesini istiyorum fakat hepsi gri gelmekte. Buna bir örnek bulamadım malesef. Elinizde bir kaynak veya yardımınız varsa bekliyorum. Teşekkür ederim.
[YARDIM] PHP Tablo Tasarımı hakkında |
15 Mesajlar | 2.679 Okunma |
A
B
C
D
E
F
G
foreach($results as $row)
{
$date=date_create($row['A']) ;
echo date_format($date,"Y/m/d");
echo '
';
}
?>
foreach($results as $row)
{
echo $row['B'] ;
echo '
';
}
?>
foreach($results as $row)
{
echo $row['C'] ;
echo '
';
}
?>
foreach($results as $row)
{
echo $row['D'] ;
echo '
';
}
?>
foreach($results as $row)
{
echo (round($row['E'],2)) ;
echo '
';
}
?>
foreach($results as $row)
{
echo (round($row['F'],2)) ;
echo '
';
}
?>
foreach($results as $row)
{
echo (round($row['G'],2)) ;
echo '
';
}
?>
$sayi=0;
$sayim=$sayi+1;
if($sayim%2==0){
$renk= ' bgcolor=”green”';
}else{
$renk= ' bgcolor=”blue”';
} ?>
A
B
C
D
E
F
G
>
foreach($results as $row)
{
$date=date_create($row['A']) ;
echo date_format($date,"Y/m/d");
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['B'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['C'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['D'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['E'],2)) ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['F'],2)) ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['G'],2)) ;
echo '
';
}
?>
$beyaz = "#fff";
$gri = "#ccc";
$stmt = $db->prepare("SELECT * FROM TABLOADI");
$stmt->execute();
echo "";
echo "
A
B
C
D
E
F
G
";
$i = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
if($i%2) {
$bg = $beyaz;
} else {
$bg = $gri;
}
echo "";
echo "".$row['A']."
".$row['B']."
".$row['C']."
".$row['D']."
".$row['E']."
".$row['F']."
".$row['G']." ";
echo " ";
$i++;
}
echo "
";
?>
ASametYildirim adlı üyeden alıntı
Hocam temel mantık bu şekilde olacak. Test etmeden yazdım baştaki ifadeyi döngü içerisine alırsanız büyük ihtimalle çalışacaktır :)
$sayi=0;
$sayim=$sayi+1;
if($sayim%2==0){
$renk= ' bgcolor=”green”';
}else{
$renk= ' bgcolor=”blue”';
} ?>
A
B
C
D
E
F
G
>
foreach($results as $row)
{
$date=date_create($row['A']) ;
echo date_format($date,"Y/m/d");
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['B'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['C'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo $row['D'] ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['E'],2)) ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['F'],2)) ;
echo '
';
}
?>
> foreach($results as $row)
{
echo (round($row['G'],2)) ;
echo '
';
}
?>
$beyaz = "#fff";
$gri = "#ccc";
$stmt = $db->prepare("SELECT * FROM TABLOADI");
$stmt->execute();
echo "";
echo "
A
B
C
D
E
F
G
";
$i = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
if($i%2) {
$bg = $beyaz;
} else {
$bg = $gri;
}
echo "";
echo "".$row['A']."
".$row['B']."
".$row['C']."
".$row['D']."
".$row['E']."
".$row['F']."
".$row['G']." ";
echo " ";
$i++;
}
echo "
";
?>