Looking for a PHP script to sort data/create pages according to fields.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dawnunder@gmail.com

    Looking for a PHP script to sort data/create pages according to fields.

    eg.

    Someone fills out 3 fields. (There will be more but this is just to
    give you an idea)

    1. Country?
    2. State?
    3. City

    I want this script to generate a web page and list the people by
    information submitted.

    eg. Everyone that put in USA will be listed on a page.

    or

    Choose California and everyone that typed in California will be listed
    on a page.

    I could also create a link with the search term at the end. eg.
    mysite/phpsearch=?mont ana

    This script will also accept data from people. So people will visit,
    type on the form and if the information is valid (not spam) then
    they'll be in a database and able to be sorted.

    Does that make sense?

  • JV

    #2
    Re: Looking for a PHP script to sort data/create pages accordingto fields.

    dawnunder@gmail .com wrote:[color=blue]
    > eg.
    >
    > Someone fills out 3 fields. (There will be more but this is just to
    > give you an idea)
    >
    > 1. Country?
    > 2. State?
    > 3. City
    >
    > I want this script to generate a web page and list the people by
    > information submitted.
    >
    > eg. Everyone that put in USA will be listed on a page.
    >
    > or
    >
    > Choose California and everyone that typed in California will be listed
    > on a page.
    >
    > I could also create a link with the search term at the end. eg.
    > mysite/phpsearch=?mont ana
    >
    > This script will also accept data from people. So people will visit,
    > type on the form and if the information is valid (not spam) then
    > they'll be in a database and able to be sorted.
    >
    > Does that make sense?
    >[/color]

    yeah makes sense ...

    1: first step is of course have the DB and table setup to store the data.
    2: write the collection page that submits data to the DB/table using get
    or post method of form submission.
    3: write the display page that takes the item entered in the form or URL
    as GET method of form and run a mysql_query on the DB/table ...
    something like this "SELECT * FROM [table] WHERE [conditional]"

    example (possibly psuedo-) code to help visualize flow:

    ----------
    MYSQL table creation. (uses 2 letter abbr for state and country

    CREATE TABLE `StoredInfo` (
    `ctry` varchar(2) NOT NULL default '',
    `city` varchar(50) NOT NULL default '',
    `stat` varchar(2) NOT NULL default ''
    ) TYPE=MyISAM;
    ----------

    collection page
    <?php
    if (isset($_GET['ctry']) and $_GET['ctry'] != ""){
    $ctry = $_GET['ctry'];
    } else {
    unset($ctry);
    }
    if (isset($_GET['stat']) and $_GET['stat'] != ""){
    $stat = $_GET['stat'];
    } else {
    unset($stat);
    }
    if (isset($_GET['city']) and $_GET['city'] != ""){
    $city = $_GET['city'];
    } else {
    unset($city);
    }

    if ($ctry and $stat and $city){
    $dbl = dbconnect(); // connect to database
    $query = "INSERT INTO StoredInfo VALUES ( '$ctry' , '$city' ,

    '$stat' )";
    mysql_query($qu ery)
    mysql_close($db l)
    }
    ?>
    <html>
    <body>
    <form method="POST" action="thisfil e">
    Country:<input type="text" name="ctry" value=""><br>
    City:<input type="text" name="city" value=""><br>
    State:<input type="text" name="stat" value=""><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>

    -----------
    display page
    <?php
    if (isset($_GET['ctry']) and $_GET['ctry'] != ""){
    $ctry = $_GET['ctry'];
    } else { unset($ctry); }
    if (isset($_GET['stat']) and $_GET['stat'] != ""){
    $stat = $_GET['stat'];
    } else { unset($stat); }
    if (isset($_GET['city']) and $_GET['city'] != ""){
    $city = $_GET['city'];
    } else { unset($city); }

    $query = "SELECT * FROM StoredInfo WHERE ";
    if ($ctry){$query .= "ctry='$ctr y'";
    if ($stat or $city){$query .= " AND ";} // or OR up to you
    }
    if ($city){$query .= "city='$cit y'";
    if ($stat){$query .= "stat='$sta t'";

    if ($ctry or $stat or $city){
    $dbl = dbconnect(); // connect to database
    $res = mysql_query($qu ery)
    mysql_close($db l)
    }
    ?>
    <html>
    <body>
    <?php
    // parse $res here as it contains the results from the query
    ?>
    <form method="POST" action="thisfil e">
    Country:<input type="text" name="ctry" value=""><br>
    City:<input type="text" name="city" value=""><br>
    State:<input type="text" name="stat" value=""><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>

    --------------
    end of code.

    this code is not likely to work if you just paste it into files. but
    gives general idea.

    dbconnect() is generic function created to connect to DB

    hope this helps without making it too easy on you :D
    JV

    Comment

    Working...