Re: [PHP] showing any mysql query in a table, help!
On Sun, Mar 19, 2006 at 05:12:06AM +, [EMAIL PROTECTED] wrote: Ok... it has to be a way to do such a thing. I do i get the column names? I can get the number of columns using mysql_num_fields() right? but what if i want to get the columns name? Wich functtion and how should i use? http://php.net/mysql_fetch_field Something like: $result = mysql_query($sql); $j = mysql_num_fields($result); for($i = 0; $i $j; $j++ ) { $field = mysql_fetch_field($result, $i); echo $field-name; } Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] showing any mysql query in a table, help!
Ok... it has to be a way to do such a thing. I do i get the column names? I can get the number of columns using mysql_num_fields() right? but what if i want to get the columns name? Wich functtion and how should i use? the goal is to make a function that prints a table that prints the result of any query in a html table. thx Pedro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] showing any mysql query in a table, help!
You could fetch the rows in an associate array. Then loop over each element in the array printing it out inside td/td tags.. print out tr before the columns, /tr after. To get the header just loop through the keys of the associative array. Whenever you want to show the header. Unless I'm misunderstanding you that should work. Chris [EMAIL PROTECTED] wrote: Ok... it has to be a way to do such a thing. I do i get the column names? I can get the number of columns using mysql_num_fields() right? but what if i want to get the columns name? Wich functtion and how should i use? the goal is to make a function that prints a table that prints the result of any query in a html table. thx Pedro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] showing any mysql query in a table, help!
[EMAIL PROTECTED] wrote: Ok... it has to be a way to do such a thing. I do i get the column names? I can get the number of columns using mysql_num_fields() right? but what if i want to get the columns name? Wich functtion and how should i use? the goal is to make a function that prints a table that prints the result of any query in a html table. thx Pedro mysql_list_fields() should do the trick for you. check out the function in the php documentation the first couple examples in the user notes area should give you some good alternatives if this function does not work for you. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php