Writing table from SQL-command
Permalink
Hi!
Sorry for my 'noob' question - i have done a lot of reading with no result. Thanks for any helpful suggestions!
I need to run a simple 'select * from TABLE' an then write the results into a table.
I have tried to create a simple function (running in a Simple PHP block) to output my sql statement:
What am I doing wrong? A simple block with fields like (SQL-Query, DB, User, PW, Server) would be very handy for me - can you point me in the right direction? Many THANKS!
Sorry for my 'noob' question - i have done a lot of reading with no result. Thanks for any helpful suggestions!
I need to run a simple 'select * from TABLE' an then write the results into a table.
I have tried to create a simple function (running in a Simple PHP block) to output my sql statement:
function SQLResultTable($Query) { $db = Loader::db( 'localhost', 'askwiki', 'PW', 'askwiki-moodle', true); $db->Execute($Query); $Table = ""; //initialize table variable $Table.= "<table border='1' style=\"border-collapse: collapse;\">"; //Open HTML Table if(mysql_error()) { $Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>"; } else { //Header Row with Field Names $NumFields = mysql_num_fields($Result); $Table.= "<tr style=\"background-color: #000066; color: #FFFFFF;\">";
Viewing 15 lines of 44 lines. View entire code block.
What am I doing wrong? A simple block with fields like (SQL-Query, DB, User, PW, Server) would be very handy for me - can you point me in the right direction? Many THANKS!
You can find an almost complete example on this page:
http://phplens.com/lens/adodb/tute.htm...
all you have to do is to add the table tags and remove the first two lines as you already get the db object using Loader::db
http://phplens.com/lens/adodb/tute.htm...
include("adodb.inc.php"); $db = NewADOConnection('mysql'); $db->Connect("localhost", "root", "password", "mydb"); $result = $db->Execute("SELECT * FROM employees"); if ($result === false) die("failed"); while (!$result->EOF) { for ($i=0, $max=$result->FieldCount(); $i < $max; $i++) print $result->fields[$i].' '; $result->MoveNext(); print "<br>\n"; }
all you have to do is to add the table tags and remove the first two lines as you already get the db object using Loader::db
You might want to check this pagehttp://phplens.com/lens/adodb/docs-adodb.htm... to get a deeper understand of adodb and avoid the mysql_* functions.