jkkenzie Posted April 11, 2008 Share Posted April 11, 2008 How do i go about creating a report from mysql database using php? which is the best option? Regards, Joseph Link to comment https://forums.phpfreaks.com/topic/100601-reports/ Share on other sites More sharing options...
poleposters Posted April 11, 2008 Share Posted April 11, 2008 Ke? I think you're question needs to be more specific. What do you want to report? Or do you just want to print everything in your database? Link to comment https://forums.phpfreaks.com/topic/100601-reports/#findComment-514518 Share on other sites More sharing options...
redarrow Posted April 11, 2008 Share Posted April 11, 2008 somethink i done quickly for you but it xml and php sorry <?php // database constants // make sure the information is correct define("DB_SERVER", "localhost"); define("DB_USER", "root"); define("DB_PASS", "password"); define("DB_NAME", "tutorials"); // connection to the database $dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die("Unable to connect to MySQL"); // select a database to work with $selected = mysql_select_db(DB_NAME, $dbhandle) or die("Could not select examples"); // return all available tables $result_tbl = mysql_query( "SHOW TABLES FROM ".DB_NAME, $dbhandle ); $tables = array(); while ($row = mysql_fetch_row($result_tbl)) { $tables[] = $row[0]; } $output = "<?xml version=\"1.0\" ?>\n"; $output .= "<schema>"; // iterate over each table and return the fields for each table foreach ( $tables as $table ) { $output .= "<table name=\"$table\">"; $result_fld = mysql_query( "SHOW FIELDS FROM ".$table, $dbhandle ); while( $row1 = mysql_fetch_row($result_fld) ) { $output .= "<field name=\"$row1[0]\" type=\"$row1[1]\""; $output .= ($row1[3] == "PRI") ? " primary_key=\"yes\" />" : " />"; } $output .= "</table>"; } $output .= "</schema>"; // tell the browser what kind of file is come in header("Content-type: text/xml"); // print out XML that describes the schema echo $output; // close the connection mysql_close($dbhandle); ?> Link to comment https://forums.phpfreaks.com/topic/100601-reports/#findComment-514520 Share on other sites More sharing options...
jkkenzie Posted April 12, 2008 Author Share Posted April 12, 2008 thanks for the code, ill try. for the other guy, i would like to select a few records from different tables and create a report that would give some sum , avarage and few other details. Thanks very much. Link to comment https://forums.phpfreaks.com/topic/100601-reports/#findComment-515358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.