Re: database lookup
- From: sk <someone@xxxxxxxxxxxxx>
- Date: Thu, 05 Oct 2006 13:06:47 GMT
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
- Prev by Date: Re-directing output from Form POST to a string
- Next by Date: Re: database lookup
- Previous by thread: Re-directing output from Form POST to a string
- Next by thread: Re: database lookup
- Index(es):