Jump to content
Sign in to follow this  
Sanitaars

php aptumsums

Recommended Posts

Sveiki visiem.

Es taisot mazu lapu esmu nonācis strupceļā.

Help :D

taisu takā testa veida lapu.

Un problēma tāda http://prntscr.com/f4ge81

Man zem ans1,ans2,ans3,ans4 ir teksta veida atbildes.

un zem ans man ir pareizā atbilde, bet jau ciparos.

un kā lai es izvadu savā lapā tikai pareizo atbildi ?

 

edit:

Es dabūju lai viņš rāda šādi, bet kā man to ans1 pārvēst uz to tekstu kas ir db? 

 - http://prntscr.com/f4goi3

$sql = "SELECT * FROM questions WHERE cat_id=$categor";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
$ansv = $row['ans']; 
		if($ansv==1){
			$gans= "ans1";
		}else if($ansv==2){
			$gans = "ans2";
		}else if($ansv==3){
			$gans = "ans3";
		}else if($ansv==4){
			$gans = "ans4";
		}
		

    echo "<b>ID:" . $row["id"]. "</b> <span style='text-decoration:underline;'>" . $row["question"]. " </span>atbilde: - <b>" .$gans. "</b> <br>";
	
	
	}
}

paldies.

Edited by Sanitaars

Share this post


Link to post
Share on other sites

tur kur tev vajag izvadīt vienkārši pieraksti 'ans'.$row['ans'] ? ja es pareizi sapratu :D 

Share this post


Link to post
Share on other sites
2 minutes ago, txt2 said:

tur kur tev vajag izvadīt vienkārši pieraksti 'ans'.$row['ans'] ? ja es pareizi sapratu :D 

Nu jā, tas labi. Bet man zem tā ans slēpjas cipari, a man vajag, lai izvadas pareizā atbilde.

tas ans ir domāts takā pareizais atbilžu variants ar cipariem.

 

Share this post


Link to post
Share on other sites

Ja es sapratu tevi pareizi tad

echo "<b>ID:" . $row["id"]. "</b> <span style='text-decoration:underline;'>" . $row["question"]. " </span>atbilde: - <b>" .$row[$gans]. "</b> <br>";
	

Tev mainīgais $gans kalpo kā row nosaukums un respektīvi sanāk tā ka
$gans = ans1
$row[$gans] == $row['ans1']

 

Share this post


Link to post
Share on other sites
21 hours ago, FaccY said:

Ja es sapratu tevi pareizi tad


echo "<b>ID:" . $row["id"]. "</b> <span style='text-decoration:underline;'>" . $row["question"]. " </span>atbilde: - <b>" .$row[$gans]. "</b> <br>";
	

Tev mainīgais $gans kalpo kā row nosaukums un respektīvi sanāk tā ka
$gans = ans1
$row[$gans] == $row['ans1']

 

īsti nav tas.

Man vajag lai viņš man izvada tekstu kur tās atbildes id=ar hz ko un kkas ar $gans

Vienu vārdu sakot.

Lai izvada to aili ($gans) kur id= tā jautājuma id.

Bet hz kā to ar kodu pateikt

Share this post


Link to post
Share on other sites
if($result->num_rows > 0){
	while($row = $result->fetch_assoc()){
		echo "<b>ID:" . $row["id"]. "</b> <span style='text-decoration:underline;'>" . $row["question"]. " </span>atbilde: - <b>" .$row['ans' . $row['ans']]. "</b> <br>";
	}
}

šādi?

  • Upvote 1

Share this post


Link to post
Share on other sites
15 hours ago, ytteroy said:

if($result->num_rows > 0){
	while($row = $result->fetch_assoc()){
		echo "<b>ID:" . $row["id"]. "</b> <span style='text-decoration:underline;'>" . $row["question"]. " </span>atbilde: - <b>" .$row['ans' . $row['ans']]. "</b> <br>";
	}
}

šādi?

Tu esi DIEVS ! :D

Paldies Tev liels, ! :) 

  • Upvote 1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.