I am blocked on a hard request to my database in php….
I would lik to display on my page a list the 10 persons (name/surname) that :
– have answered “1” to 3 questions (question1/question2/question3)
– and have answered at the question4 the closest number of participations (positive or negative sens)
Well i know how to determine my global number of paticipation :
$query_count = "SELECT COUNT(*) AS Nb FROM my_table";
$result_count = mysql_query($query_count) or die(mysql_error());
while($row = mysql_fetch_array($result_count)){
echo "Participations : ". $row['Nb'];
echo "<br />";
$count = $row['Nb']; // i create a $count var for next steps
Then i know how to display a request in table :
$query = "SELECT id,name,surname FROM my_table ORDER BY id";
$result = mysql_query($query);
// Recuperation des resultats
while($row = mysql_fetch_row($result)){
$id = $row[0];
$name = $row[1];
$surname = $row[2];
echo "<tr>\n
<td>$id</td>\n
<td>$name</td>\n
<td>$surname</td>\n
</tr>\n";
}
But in my $query i don’t know how to say :
show the 10 row WITH name,surname AND answer=1 to question1,2and3 AND
question4 is closer to number of participations (less, equal or more)
Do you have an idea?
Thanks!!!
The first part of your question is elementary:
WHERE answer IN (1,2,3)after you make the appropriate join. Since I don’t have your full schema I can’t help with specifics, but here is a rough example:The second half is vague. Please clarify what you mean by “closer to number of participations (less, equal or more)”.