> HI all > I'm trying to do the following > >----------------------------------------------------------------------------------------------------------------------------------------------- > # want to select (just preparing) every thing from the table PERSON > where i don't know the deptID yet. > $per = $dbh->prepare("SELECT * FROM person WHERE deptID = ?"); > > # selecting deptID from the table ACCOUNT, say with some condition > $acc = $dbh->prepare("SELECT deptID FROM account WHERE ....; > > $acc->execute() > or die "Can't execute the SQL statment: $DBI::errstr\n"; > > while ( @accRow = $acc->fetchrow_array ) { > # For each deptID I get from the ACCOUNT table, I want all the info from > the PERSON table > $per->execute($accRow[0] ) > or die "Can't execute the SQL statment: > $DBI::errstr\n";
The statements above are all part of a subroutine, and not meant to be executed as individual commands. Here's what is on the page you referenced: sub age_by_id { # Arguments: database handle, person ID number my ($dbh, $id) = @_; my $sth = $dbh->prepare('SELECT age FROM people WHERE id = ?') or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute($id) or die "Couldn't execute statement: " . $sth->errstr; my ($age) = $sth->fetchrow_array(); return $age; } You have to pass this subroutine 2 arguments when you execute it: $dbh and $id before it will work. -- /* All outgoing email scanned by Norton Antivirus 2002 */ Amer Neely, Softouch Information Services W: www.softouch.on.ca E: [EMAIL PROTECTED] V: 519.438.5887 Perl | PHP | MySQL | CGI programming for all data entry forms. "We make web sites work!" --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php