Re: [PHP-DB] Stuck on basic concept, how to .. here's how

2004-03-20 Thread dogu
John,

Thanks, you just saved me a whole bunch of time!  That's too bad.  I'm 
guessing that the process of re-establishing a resource isn't too 
intensive so it's not a choke point for any application.  It's 
interesting to see how different languages attack similar problems

Have a great weekend.

Doug

John W. Holmes wrote:
You can't pass resources. You connect on each PHP page. Put _that_ in a 
function to make it easy. :)

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Stuck on basic concept, how to .. here's how

2004-03-19 Thread dogu
John,

Your remark got me pointed in the right direction - I wasn't thinking 
about a second form.  Figuring out the syntax took a while, but it's 
working.  I need to do some clean up to make it a bit more elegant, but 
the bones are there.

Todo:
Disconnect the MySQL session.
Figure out a way to pass the db connection to the 2nd file rather than 
reconnecting.
Convert everything to functions where it makes sense.
Play with other other form construction - embed php in html rather than 
embedding html in php, figure out other methods to pass data between php 
and html.

Thanks for the help.

Doug

For anyone following the thread who might need to know...

Two files, both php.

First one returns a list of sites and launches the second form.
The second one uses the selected site name to return the password.
File 1:

html
body
form action=getpw.php method=get
?php

// connect to db
$db = mysql_connect(localhost);
mysql_select_db(test,$db);
$dbtbl = mysql_select_db(test,$db);
// build query
$sitequery = SELECT site from sitedata order by site;
// generate result set
$siteresult = mysql_query($sitequery);
// use results
echo Select a site from the list below: ;
echo brbr;
echo select name='website';
while($siterow = mysql_fetch_array($siteresult))
echo option 
value='.$siterow[site].'.$siterow[site]./option;
echo /select/td;

?
br
br
input type=submit /
/form
/body
/html
File 2 - getpw.php
The site you selected is ?php echo $_GET['website']; ?.
br
br
The password is
?php
// connect to db
$db = mysql_connect(localhost);
mysql_select_db(test,$db);
// build query
$pwquery = SELECT password from sitedata where 
site=.\.$_GET['website'].\;
// generate result set
$pwresult = mysql_query($pwquery);
$sitepw = mysql_data_seek($pwresult,0);
while($sitepw = mysql_fetch_array($pwresult))

echo $sitepw[password];
echo br;
echo query is .$pwquery;
?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Stuck on basic concept, how to .. here's how

2004-03-19 Thread John W. Holmes
dogu wrote:

Figure out a way to pass the db connection to the 2nd file rather than 
reconnecting.
You can't pass resources. You connect on each PHP page. Put _that_ in a 
function to make it easy. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php