Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use wpdb to connect to a custom db, then I use the following query:

$my_row = $wpdb_c->get_results("SELECT Employee.Name, Area.Name, Area.Region FROM Area INNER JOIN Employee ON Area.ID = Employee.Area_ID WHERE Employee.ID = " . get_the_ID());

How do i refer to each of the Name columns from the Employee and Area tables? I tried $my_row[0]->Area.Name but it only returned the string 'Name'.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Modify your query and use tha SQL alias as

$my_row = $wpdb_c->get_results("SELECT Employee.Name as Employe_Name, Area.Name as 
Area_Name, Area.Region as Area_Region FROM Area INNER JOIN Employee ON Area.ID = 
Employee.Area_ID WHERE Employee.ID = " . get_the_ID());

then in your code use

$my_row[0]->Area_Name
share|improve this answer
1  
sweet, i actually did this while waiting for an answer. man, so i can't use the table.column? i'll have to be aware of that, then. thanks again, @keatch –  Ana Ban Apr 8 '12 at 4:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.