Displaying by using alternate method avoiding loopings
Posted: Fri Oct 05, 2007 11:35 pm
I have a table from which i have to display like,
result_details
res_det_id (pk, auto_inc)
question_id
numbers
marks
character_matching
Numbers matching 5 characters are:
matching character numbers
.....
and below is the code i am using to display. It is working fine, but is it possible to make the whole thing in one query. Instead of writing a query to get max number and then looping every time, as it will take more resource and time.
result_details
res_det_id (pk, auto_inc)
question_id
numbers
marks
character_matching
Numbers matching 5 characters are:
matching character numbers
.....
and below is the code i am using to display. It is working fine, but is it possible to make the whole thing in one query. Instead of writing a query to get max number and then looping every time, as it will take more resource and time.
Code: Select all
$query_numbers=mysql_query("SELECT MAX(character_matching) FROM results WHERE question_id=27");
$fetch_max=mysql_fetch_array($query_numbers);
$max_number=$fetch_max['MAX(character_matching)'];
$result_details="<form method='post' action='final_result_edit.php'><table border=1 width='400'>";
if($max_number >0)
{
while($max_number >=1)
{
$query_results=mysql_query("SELECT * FROM result_details WHERE character_matching=$max_number");
if(mysql_num_rows($query_results)>0)
{
$result_details.="<tr><td colspan='2' align='center'>Numbers matching $max_number characters are: </td></tr>";
while($fetch_result=mysql_fetch_array($query_results))
{
$numbers=$fetch_result['numbers'];
$marks=$fetch_result['marks'];
$result_details.="<tr><td>$numbers</td> <td><input type='text' name='mark_text[$marks]' value='$marks'></td></tr>";
}
}
$max_number--;
}
$result_details.="<tr><td align='center' colspan='2'><input type='submit' name='submit' value='submit'></td></tr></table></form>";