Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting data from 2 tables

Status
Not open for further replies.

skosterow11

IS-IT--Management
Dec 20, 2006
6
US
Heya guys and gals -

i search the archives and cant find exactly what im looking for - if this is a repost - 1st i applogize and if you could send me down the right path would be much apprishiated!

Im looking to get data from 2 tables based on a where clause from 2 tables:

my $sth = $dbh->prepare(qq{ SELECT db_student.id, db_student.firstname, db_student.lastname, db_student_classes.gpa AS GPA, db_student_classes.attendance AS ATTENDANCE FROM db_student WHERE db_student_classes.customer_id = '$CUSTOMER::ID' AND db_student_classes.class_id = '$CLASS::ID' ORDER BY db_student.lastname });

NO THIS IS NOT A SCHOOL project - working on some testing software for my company.

Its failing saying it cant find db_student_classes. But the TABLE IS THERE in MySQL.

DBD::mysql::st execute failed: Unknown table 'db_student_classes' in field list at C:\Documents and Settings\skosterow\Desktop\Web\testanything.net\customers\classes\view.pl line 133.
DBD::mysql::st fetchrow_array failed: fetch() without execute() at C:\Documents and Settings\skosterow\Desktop\Web\testanything.net\customers\classes\view.pl line 134.




ANY help wold be appreshiated thanks in advance!

(Please dont post the answer - or ill never learn anything - if you know of a good tutorial - or document - i'd appreshiate that even more)
 
Okay Im a real DORK!

hahah i answered my own question - but for anyone else that faces this here is the CORRECT CODE!

my $sth = $dbh->prepare(qq{ SELECT db_student.id, db_student.firstname, db_student.lastname, db_student_classes.gpa AS GPA, db_student_classes.attendance AS ATTENDANCE FROM db_student, db_student_classes WHERE db_student_classes.customer_id = '$CUSTOMER::ID' AND db_student_classes.class_id = '$CLASS::ID' ORDER BY db_student.lastname });

i forgot the FROM DB!

dohhhhhhh! :)
 
Okay now im really lost!

Seems that now the thing ONLY pulls the FIRST db_student_classes.attendance AS ATTENDANCE and never pulls the other ones

IE - the first record:
db_student_classes.attendance AS ATTENDANCE = 100

but the second record:
db_student_classes.attendance AS ATTENDANCE = 97.50

yet it STILL keeps 100!!!

HELP!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top