Jump to content

Recommended Posts

Hi,

Ihave created a database which is hosted in a server. I need to filter certain data and display it on a webpage. The requirments are as follows

My table has  columns (Career Field,Career Name,Name of University,Name of Program,Program,Zip Code,City,State,Website Link,E-Mail,First Name,Last Name,Address 1,Phone)

So my webpage needs to have a combo box for user to select input as follows
1.State (Drop-Down menu  All the states in USA )
2. City  (user type the city)
3. Career (Drop-Down menu[Flight Management ] [Engineering Air] [Traffic Control]
4. Level of Education (Drop-Down menu [undergrad] [Grad] [POstgrad])

When the user select all the values the webpage should filter the records for user entered values.....

I have done the coding a bit ..help me how to pull data when user selects data from combo boxes.


My code is as follows

<!DOCTYPE html>
<html>
State
<select name="state">
    <option value="AL">AL</option>
    <option value="AK">AK</option>
    <option value="AZ">AZ</option>
    <option value="AR">AR</option>
    <option value="CA">CA</option>
    <option value="CO">CO</option>
    <option value="CT">CT</option>
    <option value="DE">DE</option>
    <option value="DC">DC</option>
    <option value="FL">FL</option>
    <option value="GA">GA</option>
    <option value="HI">HI</option>
    <option value="ID">ID</option>
    <option value="IL">IL</option>
    <option value="IN">IN</option>
    <option value="IA">IA</option>
    <option value="KS">KS</option>
    <option value="KY">KY</option>
    <option value="LA">LA</option>
    <option value="ME">ME</option>
    <option value="MD">MD</option>
    <option value="MA">MA</option>
    <option value="MI">MI</option>
    <option value="MN">MN</option>
    <option value="MS">MS</option>
    <option value="MO">MO</option>
    <option value="MT">MT</option>
    <option value="NE">NE</option>
    <option value="NV">NV</option>
    <option value="NH">NH</option>
    <option value="NJ">NJ</option>
    <option value="NM">NM</option>
    <option value="NY">NY</option>
    <option value="NC">NC</option>
    <option value="ND">ND</option>
    <option value="OH">OH</option>
    <option value="OK">OK</option>
    <option value="OR">OR</option>
    <option value="PA">PA</option>
    <option value="RI">RI</option>
    <option value="SC">SC</option>
    <option value="SD">SD</option>
    <option value="TN">TN</option>
    <option value="TX">TX</option>
    <option value="UT">UT</option>
    <option value="VT">VT</option>
    <option value="VA">VA</option>
    <option value="WA">WA</option>
    <option value="WV">WV</option>
    <option value="WI">WI</option>
    <option value="WY">WY</option>
</select>


    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        $con = mysqli_connect("localhost", "username", "password", "table");
// Check connection
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }

        $result = mysqli_query($con, "SELECT * FROM College");

        echo "<table border='1'>
<tr>
<th>Name</th>
<th>Zip</th>
</tr>";

        while ($row = mysqli_fetch_array($result)) {
            echo "<tr>";
            echo "<td>" . $row['First_Name'] . "</td>";
            echo "<td>" . $row['Zip_Code'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";

        mysqli_close($con);
        ?>
    </body>
</html>
Edited by fenway
code tags
Link to comment
https://forums.phpfreaks.com/topic/283143-database-help/
Share on other sites

The drop down list (<select></select>) needs to be enclosed in a form (<form></form>) that is the the body (<body></body>) of the webpage.

 

How to add a form to a webpage

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/My_first_HTML_form

 

When a form is submitted you can accss the forms values using the $_GET or $_POST superglobals.

Information on how PHP deals with forms

http://php.net/manual/en/tutorial.forms.php

http://uk3.php.net/manual/en/language.variables.external.php

 

To filter data in your query you'd use the WHERE clause

http://www.tutorialspoint.com/mysql/mysql-where-clause.htm

Link to comment
https://forums.phpfreaks.com/topic/283143-database-help/#findComment-1454731
Share on other sites

Avoid spaces in column names.

 

Don't duplicate values like University Name in  every record. Normalize the data http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360

Link to comment
https://forums.phpfreaks.com/topic/283143-database-help/#findComment-1454736
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.