Re: database lookup
- From: "Dano" <dan@xxxxxxxxxx>
- Date: 5 Oct 2006 06:19:41 -0700
Yep, I think that's how you'll have to go. Display the "top level"
data, like this, in PHP:
<?
echo "<a
href=\"link_to_page.php?identifying_data=".$row["data_field"]."\">Councilman</a>";
?>
The link takes them to the "link_to_page.php," and the appended data
("?identifying_data=".$row["data_field"]."\") is the data to be used in
an SQL query on the page. You can re-use the code I showed before to do
the query on the subsequent page, and display the "drill down" data.
The thing with PHP and MySQL is that you need the user to do an action
- either click a form button or click a "loaded" link as in my example
above - before the code will do something. It hasn't yet evolved to the
stage where it "knows" what the user wants, and "pre-serves" that
information - a fact some former un-tech-savvy bosses of mine never
seemed to understand. ;) You need to "lead" the user along a logical
PHP/MySQL functionality path.
Hope that helps!
sk wrote:
Thanks Dano, but I have all that done. My question/problem is displaying
either or both "Commissions" / "Councilpeople" from the database. This I
can do at this time, however, how do I let the user select say a
councileperson, that that data and query the database for the
commissioins they are on OR select a commission and then get a list of
all councilpersons on that commission.
I tried to state that I have the database designed and implemented but I
do not know (at this time) how to display the above, take the answer and
query the database again and display.
Dano wrote:
OK, I'll take a stab at answering.
First, you have to connect to the database. I use a separate file,
which I call "connect.php." I use a single file which I reference as an
"include" on all the pages I have. That way, if something in the
connection changes - such as a change in server name, username, or
password - I only have to make the change in ONE file, and not in the
hundreds of files on my sites. Here's the code for the "connect.php"
file:
<?
$db = mysql_connect("server_name", "database_username",
"database_password");
if (!$db)
{
echo "error!";
}
mysql_select_db("database_name");
?>
Of course, substitute your own values for server name, username,
password and database name. Save it in a separate file, with a ".php"
file extension.
Now comes the code for the main page:
<?
include("connect.php");
$query = "select * from table_name";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><a
href=\"select_me.php?vital_data=".$row["field_name"]."\">".$row["field_name"]."</a><p>";
}
?>
The "include" function "inserts" the code from connect.php into the
code on the page, just as if you'd written it there. The remainder of
the code sets the query string, executes the query, and sets the
results from the recordset into an array ($row), then loops through the
array. When I display the field, I put it in a simple link ("a href")
which passes the data attached to the URL to the "select_me.php" page.
You can use similar code just about any way you want to do it,
including as a radio button, a select list, etc. You can also write
some JavaScript into your PHP code that would "fire" the action upon a
change ot selection of the item in a form. Really, you're limited only
by your imagination as to what you can do. Of course, you would
probably have more than one field name to display data for, but
hopefully, the code above will give you the idea, and you can expand it
from there.
Good luck!
Johnny wrote:
"someone" <someone@xxxxxxxxxxxxx> wrote in message
news:mmkQg.79935$QM6.40595@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Could someone direct me to a site that would help me with the following:
Have database setup and loaded. Want to create web page that will use
database to do lookup of database on screen and allow selection of
field. Ie... lookup council member in lookup window, select and have
proper/correct committees councilperson belongs to appear.
TIA
start with google, search for
PHP MySql tutorial
and try the various hits.
.
- Follow-Ups:
- Re: database lookup
- From: Dano
- Re: database lookup
- References:
- Re: database lookup
- From: sk
- Re: database lookup
- Prev by Date: Re: database lookup
- Next by Date: Re: database lookup
- Previous by thread: Re: database lookup
- Next by thread: Re: database lookup
- Index(es):
Relevant Pages
|