I have voting system in my site and i want to check that user has upvoted,downvoted or not. To reduce the no. of queries i selected complete table containing id equals to user id from voting table table schema for vote table is table schema for answer table is
$query=SELECT answer_id,user_id,vote FROM vote WHERE user_id='{$_SESSION["id"]}'
$result1=mysql_query($query);
$array=mysql_fetch_array($result1);
now when i fetch the answers of question i want to check that if this user has voted or not if answer_id has found in this array than than i want to find the value of vote ?
code is
$query1="SELECT * FROM answers WHERE question_id='{$question_id}'";//$question_id is id of question
$result=mysql_query($query1);
if($result){
While ($row=mysql_fetch_arrar($result)){
if(in_array($row["id"],$array){
echo $array["vote"];
}
}
}
I am confused how to fetch two array together...?This query only works for first value because i am not using while loop in $array,Can anybody help me..?