I am taking a database course, and I have an assignment that I hope someone can point me in the right direction.
Write a PHP program that allows the user to select fields and number of records they want displayed from a database and then displays them in HTML format.
That is all I'm going off of, so I apologize if it's vague. I can connect to a db fine, I am lost as how to get the user to query and then return the results.
thanks.
10-23-2012, 06:01 PM
b073r
Hi,
you have to create html form and then pass the data from the to your query,
It will look similar to this:
HTML FORM
HTML Code:
<form action="" method="POST"> <select name="field">
Choose a field: <option>field1</option> <option>field2</option>
Number of records: <input type="text" name="number" /> <input type="submit" name="ok" value="show" /> </form>
PHP code:
PHP Code:
if(isset($_POST['ok'])){
$field=$_POST['field'];
$num=$_POST['number'];
$query=mysql_query("SELECT ".$field." FROM `yourDB` limit 0,".$num." ");