dogbiter Posted May 25, 2008 Share Posted May 25, 2008 ok i'm useing the new 5.0.12 mysql version. and PHP Version 5.2.4-2ubuntu5.1 so my question is i know how to dynamically create table rows and fill them with what's in the table selected but i don't know how to get the titles of the columns that i'm looking at. this is how i'm getting the info posted on the site, very basic. <? for ($i=0; $i<$query3; $i++){ echo "<tr>"; for ($d=0; $d<$query4; $d++){ echo "<td>".$query2[$d]."</td>"; } echo "</tr>"; } ?> </table> if you can help me get the titles above the columns i would be grateful. Quote Link to comment https://forums.phpfreaks.com/topic/107170-getting-titles/ Share on other sites More sharing options...
Barand Posted May 25, 2008 Share Posted May 25, 2008 try this function <?php include 'db.php'; //connnection stuff function table2Table($query) { $result = mysql_query($query) or die (mysql_error()); $str = "<TABLE border='1' cellpadding='4'>\n"; // column headings $str .= "<tr>\n"; while ($fld = mysql_fetch_field ($result)) { $str .= "<th>{$fld->name}</th>\n"; } $str .= "</tr>\n"; // list data while ($row = mysql_fetch_row($result)) { $str .= "<tr>\n"; foreach ($row as $field) { $field = $field=='' ? ' ' : $field; $str .= "<td>$field</td>\n"; } $str .= "</tr>\n"; } $str .= "</TABLE>\n"; return $str; } // // call function // echo table2Table("SELECT * FROM tablename"); // your query here ?> Quote Link to comment https://forums.phpfreaks.com/topic/107170-getting-titles/#findComment-549822 Share on other sites More sharing options...
dogbiter Posted May 26, 2008 Author Share Posted May 26, 2008 thanks i'll see if i can get that to work LOL just getting back into php for like the 100th time so i'll pull it apart and try to understand it. thanks Quote Link to comment https://forums.phpfreaks.com/topic/107170-getting-titles/#findComment-550181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.