Jump to content

Embedded queries??


ryan.od

Recommended Posts

I have a database with the following two tables:

 

1. job

2. company

 

Each job entry has its own info as well as a job_comp_id column that corresponds to a a comp_id column in the company db table.

 

This works fine. No problems separating info and getting that info into the db.

 

The most simple way I can explain my issue is as follows: Within a while loop that is working its way through my first $row array (generated from $result = mysql_query($sql)), how can I query a different table? Kind of like 'embedded queries'.

 

I totally understand why I separated the companies from the jobs. However, now it is a pain in the butt trying to work with both tables in one page.

Link to comment
Share on other sites

Just query it as you would any other time.

 

Quick example:

while ($row = mysql_fetch_row($result)) {
$result2 = mysql_query("SELECT blah FROM company WHERE id=$row[4]");
echo mysql_result($result2,0);
}

 

Are you sure you don't need a JOIN instead?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.