hello guys, i have spent one week on this problem but untill now my proplem does not soloved.
my code is about rating system and i can not insert vote for question that i voted for, throught this code vote will insert for the all displays question.
note that i have while inside while to display the questions and it's answers.
i have tree tables as this:
questions:
| id | question|
answer:
| answer | id_answer | id_question|
vote:
| id_vote | id_question | id_answer | ip
<html>
<head>
<link href='style.css' type='text/css' rel='stylesheet'/>
<meta charset="utf-8"/>
</head>
<body>
<?php include "config.php";?>
<form action='vote.php' method='post'>
<div id='container'>
<?php
$select_question=mysql_query("select * from question order by id desc ")or die(mysql_error());
while ($object_qu=mysql_fetch_object($select_question)){
$id_question=$object_qu->id;
$question=$object_qu->question;
echo"<div id='headblcok'>$question</div>";
///////////////////////////////insert vote into database
if(!empty($_POST['answer'])){
$ip=getenv("remote_addr");
$id_answer_vote=$_POST['answer'];
if($_POST['vote']){
$ip=getenv("remote_addr");
$check_ip=mysql_query("select * from answer where id_question='$id_question'");
$get_target_question=mysql_fetch_object($check_ip);
$get_target_question->id_question;
echo"<br/>";
$insert_vote=mysql_query("insert into vote values('','$id_question','$id_answer_vote','$ip')")or die(mysql_error());
}
}
/////////////////////////////////////////////////////////
?>
<?
$select_answer=mysql_query("select * from answer where id_question='$id_question'")or die(mysql_error());
$num_answer=mysql_num_rows($select_answer);
////////////////////////////////looping answer's question
while ($object_ans=mysql_fetch_object($select_answer)){
$id_answser=$object_ans->id_answer;
$id_question_fromanswer=$object_ans->id_question;
$answer=$object_ans->answer;
$select_per=mysql_query("select * from vote where id_question='$id_question' and id_answer='$id_answser'");
$num_votes=mysql_num_rows($select_per);
$fore_vote=ceil(($num_votes/$num_answer)*100)/6;
///////////////////////////////////////////////
echo"<input type='radio' name='answer' value='$id_answser'/> ";
echo"$answer ($num_votes Votes)<div id='block'> <img src='v.png' width='$fore_vote' height='20'/> </div>";
echo"<br/>";
}
}
?>
<input type='submit' value='Vote' name='vote'/>
</form>
</div>
</body>
</html>