[PHP-DB] results of query
What does everyone typically use to display the results of a query. For example, I have a database that has a series of subjects and grades. If I select * from the table, I want a nice way for the data to be displayed. In cold fusion, I can simply use a grid that dynamically fills in. Can I do this with php? Thanks, Eddie -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] results of query
It depends what you want to do with it. To display it in HTML, you can write them in a 2-D array: myarray[$i][$j], where $i is the row nb and $j the column nb, and write two nested loops. To export them to Access, CSV, ... you can issue your query through Access ODBC. You can then save as a CSV. Very simple and effective. Ignatius - Original Message - From: Edward Peloke [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, October 07, 2002 10:07 PM Subject: [PHP-DB] results of query What does everyone typically use to display the results of a query. For example, I have a database that has a series of subjects and grades. If I select * from the table, I want a nice way for the data to be displayed. In cold fusion, I can simply use a grid that dynamically fills in. Can I do this with php? Thanks, Eddie -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] results of query
Will this work (assume you're using mysql): function printresult ($rs) { if ($a = mysql_fetch_assoc($rs)) { // Print header echo 'tabletr'; foreach (array_keys ($a) as $v) echo 'th' . $v . '/th'; echo '/tr'; while ($a) { echo 'tr'; foreach ($a as $v) echo 'td' . $v . '/td'; echo '/tr'; $a = mysql_fetch_assoc($rs); } echo '/table'; } else echo 'bNo results found./b'; } You can embellish the resulting HTML code as needed. (Also, please note that I'm doing this from memory... so it might not work right off ;) Marco On Mon, 2002-10-07 at 16:07, Edward Peloke wrote: What does everyone typically use to display the results of a query. For example, I have a database that has a series of subjects and grades. If I select * from the table, I want a nice way for the data to be displayed. In cold fusion, I can simply use a grid that dynamically fills in. Can I do this with php? Thanks, Eddie -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] results of query
What does everyone typically use to display the results of a query. For example, I have a database that has a series of subjects and grades. If I select * from the table, I want a nice way for the data to be displayed. In cold fusion, I can simply use a grid that dynamically fills in. Can I do this with php? There is no automatic way to do it with PHP. You have to write the code to display it yourself and this depends on how you want to display it. If you just want to display it in a table, then you can write a generic function to display column names and values in a table given a result set. Assuming $result is a result set from any query. echo table; while($row = mysql_fetch_row($result)) { echo trtd . implode(/tdtd,$row) . /td/tr\n; } echo /table; Adapt to your needs to add error checking, empty fields, header row, etc. You can use the mysql_field_name() functions to get the field names from the result set to create your header row, so you don't actually have to know the names from the query. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php