www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with assignment

  1. #1
    Join Date
    Oct 2012
    Posts
    3

    Help with assignment

    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.

  2. #2
    Join Date
    Oct 2012
    Posts
    13
    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." ");

    while(
    $row=mysql_fetch_array($query)){
    echo
    '<p>'.$row.'</p>';

    It is not checking the any error or something, if you want more functional script write to PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles