Re: mysql results, arrays, and for loops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, here is my solution (one of the possible) it is tested so it should work
fine:

<?php
$recordset=mysql_query($query);
$num_righe=mysql_num_rows($recordset);

// here starts the dinamyc table
echo "<TABLE align=\"left\" border=\"1\" cellspacing=\"2\" cellpadding=\"2\"
width=\"80%\">\n<tr>";

$record= mysql_fetch_array($recordset, MYSQL_ASSOC);
foreach ($record as $k =>$val)
{
    echo "<td><b>$k</b></td>\n"; // print the field name in the first row of
the table
    for ($i=0;$i<$num_righe;$i++)
    {
        echo "</tr>";
        mysql_data_seek($recordset,$i);
        $record = mysql_fetch_array($recordset, MYSQL_ASSOC);
        foreach ($record as $val){
        echo "<td>$val</td>\n"; // print the result of query, starting under
1st row
    }
}
mysql_free_result($recordset);
mysql_close();
echo "</tr></table><br>";
?>
Let me know if it fits your problem.
Best regards
Francesco Basile

"Philip Thompson" <prthomp@xxxxxxxx> ha scritto nel messaggio
news:539DCBEC-BBB2-11D8-8631-000393C795C4@xxxxxxxxxxx
> Hi all!
>
> I am using a select statement to obtain all the dates whenever someone
> submitted a problem in a database. Well, I want to get the result
> (which could be multiple dates) and then print that in a table format
> with some other information on a webpage. So I want to use a FOR loops
> and go through each of the dates and dynamically create a table.
>
> My question is: how do I store the results of the select query? Would I
> want to store them in an array, and then just parse through each
> element of the array, and what is the syntax for that? Or is there a
> better way?
>
> Thanks,
> ~Philip

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux