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

This is a discussion on Looking for a PHP script to sort data/create pages according to fields. within the PHP Language forums, part of the PHP Programming Forums category; eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-18-2004
dawnunder@gmail.com
 
Posts: n/a
Default 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=?montana

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?

Reply With Quote
  #2 (permalink)  
Old 12-30-2004
JV
 
Posts: n/a
Default Re: Looking for a PHP script to sort data/create pages accordingto fields.

dawnunder@gmail.com wrote:
> 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=?montana
>
> 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?
>


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($query)
mysql_close($dbl)
}
?>
<html>
<body>
<form method="POST" action="thisfile">
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='$ctry'";
if ($stat or $city){$query .= " AND ";} // or OR up to you
}
if ($city){$query .= "city='$city'";
if ($stat){$query .= "stat='$stat'";

if ($ctry or $stat or $city){
$dbl = dbconnect(); // connect to database
$res = mysql_query($query)
mysql_close($dbl)
}
?>
<html>
<body>
<?php
// parse $res here as it contains the results from the query
?>
<form method="POST" action="thisfile">
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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0