ryan.od Posted June 29, 2007 Share Posted June 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted June 29, 2007 Share Posted June 29, 2007 I don't follow; can you give more examples? Do you want a subquery or a join? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 29, 2007 Share Posted June 29, 2007 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? Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted June 29, 2007 Share Posted June 29, 2007 Grab both job and company information with a join, also use group_concat if you want a single job record with a column that contains all the associated company records instead of duplicate rows of job records along side respective company record. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.