PHP gets the data from the database and uses it outside during the loop

advertisements
<?php
$q=select * from students where (dynamic for user searching)
$qry=mysql_fetch_array($q);
while($row=mysql_fetch_array())
{
   **// i do not need data here?**
}
?>
< table>
< tr>< td><?php echo **$row[?][?];** ?>< /td>< td><?php echo **$row[?][?];** ?>< /td>...< /tr>
< tr>< td><?php echo **$row[?][?];** ?>< /td>< td><?php echo **$row[?][?];** ?>< /td>...< /tr>
....
< /table>

In need to generate a dynamic report in html table format the html table rows and columns are static for results so i cant use echo with in while loop i have to access it out side while loop i have an idea of selecting single row single column for each cell of table separatly but it will be time consuming and length any alternative or solution?


You don't have to use a while loop. You can fetch the data as you need it.

$row1 = mysql_fetch_array($qry);
$row2 = mysql_fetch_array($qry);

I don't like doing this though because you have to keep track of the resource ($qry in this case) and you have to keep typing mysql_fetch_*() so I tend to load results into an array before I use them.

$result = array();
while($row=mysql_fetch_object($qry))
{
    $result[] = $row;
}