|
Posted by Dano on 09/21/06 12:36
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@somewhere.org> wrote in message
> news:mmkQg.79935$QM6.40595@bgtnsc05-news.ops.worldnet.att.net...
> > 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.
Navigation:
[Reply to this message]
|