On v, 2007-01-21 at 01:28 -0800, pub wrote: > On Jan 18, 2007, at 2:43 AM, Németh Zoltán wrote: > > > first, do you want to allow several jobs for the same company to be > > > > stored in the DB and appear on the page, right? (if not, then why > > are > > > > you storing them in separate tables?) > > > > > Yes, I have the name of the company with address etc in the "client" > table > and all the jobs in the "job" table, so that I can display several > jobs per client > > second, you should do it with one query I think > > > > > > something like "SELECT t1.*, t2.* FROM client t1, job t2 WHERE > > > > t1.companyId=t2.companyId ORDER BY t1.companyId" > > > > > > and then you can do all stuff in one loop > > > > > > while ($aaa = mysql_fetch_array($result)) > > > > > > and you don't need that foreach stuff at all (which also seems to be > > > > screwed up...) > > > > I am working on my query as you suggested. I have a joint query that > seems to work except that I get the name of the company twice. Could > you please help me figure out how to make it echo the company once and > list all the jobs next to it on the same line and start a new line > with the next company? > > ehh, I thought you want the jobs on separate lines, sorry. this can be achieved for example like this: $prev_cname = ""; while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC)) { if ($aaa['companyName'] != $prev_cname) { echo "<span class='navCompany'>{$aaa['companyName']}</span>"; } echo "<span class='navArrow'> > </span><span class='navText'><a href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span>"; if ($aaa['companyName'] != $prev_cname) { echo "<br/>\n"; $prev_cname = $aaa['companyName']; } } hope that helps Zoltán Németh > Here is the code I have now: > > > $query = "SELECT client.companyName, job.jobType, job.pix, job.info, > job.url > FROM client, job > WHERE client.companyId=job.companyId > AND client.view='yes' > order by client.companyName"; > > > > $result = mysql_query($query) > or die ("Couldn't execute query"); > > while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC)) > { > echo "<span class='navCompany'>{$aaa['companyName']}</span><span > class='navArrow'> > </span><span class='navText'><a > href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span><br>\n"; > } > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php