Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:58:58+00:00 2026-05-29T19:58:58+00:00

I am trying to query the department name from one table, using the id

  • 0

I am trying to query the department name from one table, using the id submitted from a form submission to another table by matching the id from the form submission to the id in the Department table.

$deptQuery =  $form->getValue('department_id');

      $q = Doctrine_Query::create()
        ->select('d.name')
        ->from('Department d')
        ->where('id = ?', $deptQuery)
        ->execute();
      ;
echo $q;

This is my output:

<pre>
Doctrine_Collection
data : Array(
   0 : Object(Department)
)
</pre>

I can get the department_id variable to display like this:

$deptQuery =  $form->getValue('department_id');
echo $deptquery;

It will show the correct id:

 5 (for example)

How can I write the query so it takes the submitted form department_id and matches it to the id in the Department table and outputs the department name?

ie rather than 5, it outputs the photography dept.

This has been addressed and resolved here. Sorry for my amateur posting.

I just needed to cut the array to one return and pull the first.

$dept = $q->fetchOne();
$dept = $q->execute()->getFirst();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:58:59+00:00Added an answer on May 29, 2026 at 7:58 pm

    There is a method call find() which does exactly what you want … use it like this :

    $dept = Doctrine_Core::getTable('Department')->find($id);
    

    The $id parameter must be a primary key – which in your case it is (im assuming). This will return a Department object matching your primary key – to get the name you can just use $dept->getName()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to optimise my query. Basically I have an Department table and a
I'm trying to query a MySQL database using an array but I'm having trouble!
I am trying to query the windows desktop search API using SQL. I have
I'm trying to query using Castle and return a strong-typed array or IList for
I'm trying to query a table, fetch all records, and save the result as
I'm trying to query a set of buldings listed on a table, these buildings
I'm trying to determine a way to query data from a MySQL database and,
I'm trying query a remote JVM with jps using jstatd, in order to eventually
I'm trying to complete this Oracle SQL query with no luck. List the department
I'm trying to query an MySql table, put all results into a combobox. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.