Jump to content

display column names from database in returned values table


Juarez

Recommended Posts

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>' );
?>










Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.