Hi. I have made one table in PHP which is having dynamic header and dynamic data. Now I want to add a new column in it which is having static header. How can I add it? Please help me. Thanks in advance.
here is the code......... <?php $uname=$_SESSION['uname']; $pass=$_SESSION['password']; $tblname=$_GET['name']; $_SESSION['tbl']=$tblname; $dbname=$_GET['db']; define( 'NL', "\n" ); define( 'TB', ' ' ); $conn = mysql_connect( 'localhost',$uname ,$pass) or die( mysql_errno().': '.mysql_error().NL ); $db=mysql_select_db($dbname,$conn) or die("Could not connect to database"); $res1 = mysql_query("SHOW COLUMNS FROM $tblname"); $cntfield=mysql_num_rows($res1); $res=mysql_query("select * from $tblname "); $cnt=mysql_num_fields($res); echo "<table border=1>"; while($arr=mysql_fetch_array($res)) { echo "<tr>"; while ($row = mysql_fetch_array($res1)) { echo "<td class=footer>"; echo "<b>"; print_r($row[0]); echo "</b>"; echo "</td>"; } echo "</tr>"; echo "<tr>"; for($i=0;$i<$cnt;$i++) { echo "<td>"; echo $arr[$i]; echo "</td>"; } echo "</tr>"; } echo "</table>"; ?>
not sure if this is what you're asking. just add another <td></td> <?php $uname=$_SESSION['uname']; $pass=$_SESSION['password']; $tblname=$_GET['name']; $_SESSION['tbl']=$tblname; $dbname=$_GET['db']; define( 'NL', "\n" ); define( 'TB', ' ' ); $conn = mysql_connect( 'localhost',$uname ,$pass) or die( mysql_errno().': '.mysql_error().NL ); $db=mysql_select_db($dbname,$conn) or die("Could not connect to database"); $res1 = mysql_query("SHOW COLUMNS FROM $tblname"); $cntfield=mysql_num_rows($res1); $res=mysql_query("select * from $tblname "); $cnt=mysql_num_fields($res); echo "<table border=1>"; while($arr=mysql_fetch_array($res)) { echo "<tr>"; while ($row = mysql_fetch_array($res1)) { echo "<td class=footer>"; echo "<b>"; print_r($row[0]); echo "</b>"; echo "</td>"; } echo "<td>static title</td>"; echo "</tr>"; echo "<tr>"; for($i=0;$i<$cnt;$i++) { echo "<td>"; echo $arr[$i]; echo "</td>"; } echo "<td>static content</td>"; echo "</tr>"; } echo "</table>"; ?> PHP:
i have tried this but it is coming in table data instead what i want is it in table header. how can i do this?
how bout replacing this echo "<td>static title</td>"; PHP: with this: echo "<td class=footer><b>static title</b></td>"; PHP: