Jump to content
Son zamanlarda artan kullanıcı hesap hırsızlıkları sebebiyle tüm kullanıcılara şifre sıfırlama maili gönderilmiştir. Lütfen güveli şifreler seçiniz. Mevcut e-mail adresinize erişemiyorsanız, en aşağıdaki destek linkinden bize ulaşınız. ×

Foreach Ve Değer Kontrolü


Recommended Posts

Merhaba arkadaşlar.
Formdan gelen veriyi foreach ile alıp explode ile parçalıyorum. Sorunum formdan seçenek işaretlenmemişse onu boş olarak göstersin. Yani ekrana Boş Bırakıldı yazılsın. Aşağıdaki resimde olduğu gibi. Ben uğraştım ama boş yazdırma işlemini yapamadım.

r2q5v1.png

sorular.php

<div class="panel panel-default">
	<div class="panel-heading"><h4 class="text-center" style="margin:3px 0 0 0"><?php echo $tyaz["test_adi"]; ?></h4></div>
</div>
	
<?php
	$id = $_GET["id"];
	$sec = @mysql_query("SELECT * FROM testler INNER JOIN sorular ON sorular.soru_test_id = testler.test_id WHERE soru_test_id = $id");
	while($yaz = @mysql_fetch_array($sec)){
?>

<!--- Sorular --->
<form id="SoruFormu" action="index.php?git=sonuc&id=<?php echo $yaz["test_id"]; ?>" method="post">
	<div class="panel panel-default">
		<div class="panel-heading"><?php echo "<b>SORU ".$yaz["soru_no"]."</b>" ?></div>
		<div class="panel-body">
			<p><?php echo $yaz["soru_metin"]; ?></p>
		</div>
			<ul class="list-group">
				
				<li class="list-group-item">
					<div class="SecenekIsaret">
						<input type="checkbox" name="cevap-<?php echo $yaz["soru_no"]; ?>" id="<?php echo $yaz["soru_no"]."-"; ?>secenek-a" value="A">
						<label for="<?php echo $yaz["soru_no"]."-"; ?>secenek-a">A) <font style="font-weight:normal"><?php echo $yaz["soru_secenek_a"]; ?></font></label>
					</div>
				</li>
				
				<li class="list-group-item">
					<div class="SecenekIsaret">
						<input type="checkbox" name="cevap-<?php echo $yaz["soru_no"]; ?>" id="<?php echo $yaz["soru_no"]."-"; ?>secenek-b" value="B">
						<label for="<?php echo $yaz["soru_no"]."-"; ?>secenek-b">B) <font style="font-weight:normal"><?php echo $yaz["soru_secenek_b"]; ?></font></label>
					</div>
				</li>
				
				<li class="list-group-item">
					<div class="SecenekIsaret">
						<input type="checkbox" name="cevap-<?php echo $yaz["soru_no"]; ?>" id="<?php echo $yaz["soru_no"]."-"; ?>secenek-c" value="C">
						<label for="<?php echo $yaz["soru_no"]."-"; ?>secenek-c">C) <font style="font-weight:normal"><?php echo $yaz["soru_secenek_c"]; ?></font></label>
					</div>
				</li>
				
				<li class="list-group-item">
					<div class="SecenekIsaret">
						<input type="checkbox" name="cevap-<?php echo $yaz["soru_no"]; ?>" id="<?php echo $yaz["soru_no"]."-"; ?>secenek-d" value="D">
						<label for="<?php echo $yaz["soru_no"]."-"; ?>secenek-d">D) <font style="font-weight:normal"><?php echo $yaz["soru_secenek_d"]; ?></font></label>
					</div>
				</li>
				
				<li class="list-group-item">
					<div class="SecenekIsaret">
						<input type="checkbox" name="cevap-<?php echo $yaz["soru_no"]; ?>" id="<?php echo $yaz["soru_no"]."-"; ?>secenek-e" value="E">
						<label for="<?php echo $yaz["soru_no"]."-"; ?>secenek-e">E) <font style="font-weight:normal"><?php echo $yaz["soru_secenek_e"]; ?></font></label>
					</div>
				</li>
			
			</ul>
	</div>
<!--- # Sorular # --->
		
<?php } ?>

<input class="btn btn-primary" type="submit" value="Testi Bitir" style="display:block!important; width:750px; margin-bottom:40px">
</form>

sonuc.php

<div class="panel panel-default">
	<div class="panel-heading"><h4 class="text-center" style="margin:3px 0 0 0"><?php echo $tyaz["test_adi"]; ?></h4></div>
</div>

<!--- Sonuç --->
<div class="panel panel-default">
	<div class="panel-body">
		<ul class="list-group">
			<?php
			if( $_POST ){
				
				$dogru 	= 0;
				$yanlis = 0;
				$bos 	= 0;
				$toplam = 0;
				
				foreach( $_POST as $anahtar => $deger ){
					$sorular = explode('-', $anahtar);
					$soruNo = $sorular[1];
					
					/*echo "<pre>"; print_r($_POST); echo "</pre>";*/

					$id = $_GET["id"];
					$sec = @mysql_query("SELECT * FROM testler INNER JOIN sorular ON sorular.soru_test_id = testler.test_id WHERE soru_test_id = $id AND soru_no = $soruNo");
					$yaz = @mysql_fetch_array($sec);
					
					$sDogru 	= '<font color="green">[ DOĞRU ]</font>';
					$sYanlis 	= '<font color="red">[ YANLIŞ ]</font> <font color="green">[ '.$yaz['soru_dogru_cevap'].' ]</font>';
					
					$durum = $deger == $yaz["soru_dogru_cevap"] ? $sDogru : $sYanlis;

					if ($deger == "")
					{
						$durum = "";
						$bos++;
					}
					else if ($durum == $sDogru)
					{
						$dogru++;
					}
					else
					{
						$yanlis++;
					}

					$toplam++;
					
					echo "<li class='list-group-item'><b>$soruNo.</b> Soruya verilen cevap : <b>$deger</b>" . (!empty($durum) ? " <b>$durum</b> " : " <font color='green'><b>[ ".$yaz['soru_dogru_cevap']." ]</b></font> ")."</li>";
					
				}
			}
			?>
		</ul>
	</div>
</div>
<!--- # Sonuç # --->

<div class="panel panel-default">
	<div class="panel-body">
		<div class="Dogrular"><span class="Sonuc">Doğru Cevap: <strong><?php echo $dogru; ?></strong></span></div>
		<div class="Yanlislar"><span class="Sonuc">Yanlış Cevap: <strong><?php echo $yanlis; ?></strong></span></div>
		<div class="BosCevap"><span class="Sonuc">Boş Bırakılan: <strong><?php echo $bos; ?></strong></span></div>
		<div class="ToplamSoru"><span class="Sonuc">Toplam Soru: <strong><?php echo $toplam; ?></strong></span></div>
		<div class="Cevaplanan"><span class="Sonuc">Cevaplanan: <strong><?php echo $toplam - $bos; ?></strong></span></div>
		<div class="Clean"></div>
	</div>
</div>

 

Edited by Abdullah 37
Link to comment
Share on other sites

  • 3 ay sonra...
faruk15725, 15 saat önce yazdı:

En basit yöntem ile formu oluşturduğun yerde bir şık daha ekle boş ilk başta hepsi boş seçili olsun boş gelenler boş geçmiş veya seçilmiş olur. 

Bu şekilde olabileceğini biliyorum ama ben şık eklemek istemiyorum. Başka bir yolu yok mu?

Link to comment
Share on other sites

  • 3 hafta sonra ...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...