Juarez Posted April 8, 2013 Share Posted April 8, 2013 Hi. I have a html seach form and a php page. basically a user can enter the column name selections in the search boxes and select the relevent columns from the database. the data is returned dynamically to a table with mysql_fetch_array but I would like the column names from the database displayed at the top of returned table. thanks //index.html <html> <head> <title>Search the Database</title> </head> <body> <form action="search_column.php" method="post"> <br /> Search ID1: <input type="text" name="column1" /><br /> Search ID2: <input type="text" name="column2" /><br /> Search ID3: <input type="text" name="column3" /><br /> <br /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> //search_column.php <?php require_once('includes/connection.inc.php'); $column1 = $_POST['column1']; $column2 = $_POST['column2']; $column3 = $_POST['column3']; $qry=mysql_query("SELECT * FROM mytable", $con); echo "<table border='3' width = '150'>"; echo "<tr> </tr>"; /* Fetching the data */ while($row=mysql_fetch_array($qry)) { echo "<tr>"; echo "<td>".$row{$column1}. "<br></td>"; echo "<td>".$row{$column2}. "<br></td>"; echo "<td>".$row{$column3}. "<br></td>"; echo "</tr>"; } echo "</table>"; print( '<a href=index.html>Go back to search</a>' ); ?> Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 10, 2013 Share Posted April 10, 2013 Try this echo "<table border='3' width = '150'>"; echo "<tr><th>{$column1}</th><th>{$column2}</th><th>{$column3}</th></tr>"; Quote Link to comment 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.