By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
JV
da*******@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
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.