Hi,
I ask a similar question but did not get a reply. I figured out a
way. The only thing I do is use one form and four tables.
I build the sql statement on the fly.
>From the from I have a hidden field that will be passed on to the php
script. Based on that variable I select the table. You can see a sample
of it on vvmm.net/search.php3
$searchstmt = "select ";
switch ($vsearch) {
case "z":
// this exec only if no choice is selected.
$searchStmt .= "";
break;
case "c":
// Select vvmmdb table. Catalog Choice
$searchStmt .= "city.city as destinazione, vvmmdb.days,
vvmmdb.periodo, vvmmdb.vitofferta, vvmmdb.curr1 as curr2, vvmmdb.url,
vvmmdb.stars, vvmmdb.club, vvmmdb.tcode from vvmmdb,city where ";
// blah blah
}
// Check if destinazione has been entered
if ($dest) {
switch ($vsearch) {
case "z":
$searchStmt .= "";
break;
case "c":
// Select vvmmdb table. Catalog Choice
$searchStmt .= "vvmmdb.cityid=$citycode and ";
$csearchStmt .= "vvmmdb.contid=$countrycode and ";
break;
// more case statements
}
I have a whole script about 800 lines. If you need it I will send it. In
fact I sent this script earlier. I finally end it with:
$stmt = substr($searchStmt, 0, strlen($searchStmt)-4);
$stmt1 = substr($searchStmt1, 0, strlen($searchStmt1)-4);
Since I do not know which options the viewer is selecting I use the above
to remove the " and" at the end of the statement.
It works for me.
Adrian
On Sun, 13 May 2001, midget2000x wrote:
> I am writing a PHP application that will operate on a MySQL database. There
> will be 4 types of forms (like catalog request, info request, etc.) calling
> the code which writes the data to the database.
>
> Since the variable names on the forms will equal the MySQL column names (as they
> should), I am wondering if there is a way for me to create my SQL statements on
> the fly so that only data passed is written. Otherwise I'll have to create 8
> types of SQL statements...INSERT (if the record, keyed by e-mail address,
> doesn't exist), and UPDATE (if the record does exist) for all 4 forms.
>
> For example, on my "add to mailing list" form, only the e-mail address is
> collected. I'd like the PHP to recognize that only the 'email' field is passed
> and create the SQL statement that only writes the e-mail to the database.
>
> Any ideas greatly appreciated!
>
> Thanks,
>
> Rory
>
> -- -----------
> providing the finest in midget technology
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]