|
Posted by Dano on 10/05/06 13:34
I should also add that you can do what I call a "recursive" page, where
the form data (or a "loaded" link, as in my example above) will call
the SAME page, and use the data passed to it to modify the page
content.
Usually, this involves using some logic - like "if" statements - and
structuring the display accordingly. It's a little more complicated,
but if you use pseudo-code and think it through logically, it's doable.
I think the basic "go from page one to page two" approach is simpler,
and may be more in line with what you can do at the present with the
skills you have.
I'd be glad to provide examples of a "recursive" page, if you want. (I
fear posting so much code, because I'm a pretty basic user, and I think
there are hordes of readers out there who're groaning over how
inelegant my solutions are! But they work, which is a good thing, in
the end! ;) )
Like I said, hope that helps, and if you'd like more help, I'll be glad
to point you in the right direction - at least as far as I know! ;)
Dano wrote:
> 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@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]
|