Jump to content

Recommended Posts

Hello, im having problems joining and 'echo' some data from mysql

 

table: 1. magazine

id - created - changed - title

 

table: 2. magazine_category

id - created - changed - fk_magazine_id - cat_title

 

table: 3. magazine_links

id - created - changed - fk_magazine_id - file_type - link

 

In tables '2&3' fk_magazine_id = table '1' id.

 

P.S Ive attaced image what is the problem, i want only to show 1 title per time not 2,3 every thing

 

 

<h2>Links</h2>
<?php
        
    $query="SELECT DISTINCT *  
FROM magazine mag  
LEFT join magazine_links magl 
ON mag.id = magl.fk_magazine_id 
RIGHT join magazine_category magc  
ON magc.fk_magazine_id = magl.fk_magazine_id 
WHERE mag.id = $_GET[employ_id]";

    
	$res = mysql_query($query); // or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
    ?> 

    <table width="100%" cellspacing="0" cellpadding="0" class="border-bluegray"> 	 
  <tbody> 
    <tr class="border-bluegray-head"> 		<td class="border-bluegray-round-tl"></td> 		<td class="border-bluegray-t-line border-bluegray-vdelimiter"></td> 		<td class="border-bluegray-t-line border-bluegray-vdelimiter"></td> 		 		 		 		 		 		 		<td class="border-bluegray-t-line border-bluegray-vdelimiter"></td> 		<td class="border-bluegray-t-line"></td> 		<td class="border-bluegray-round-tr"></td> 	</tr>

   	 
    <tr class="border-bluegray-head border-bluegray-head-text"> 		<td class="border-bluegray-l-line"></td> 		<td class="border-bluegray-vdelimiter border-bluegray-prb"><b><font class="tableheadtext"><a name="bx_integration"></a>
	<?php echo($row['cat_title']); ?></font></b></td> 		<td align="center" class="border-bluegray-vdelimiter border-bluegray-plrb"><b><font class="tableheadtext">
	.pdf <img width="18" height="18" src="/images/icons/pdf_doc.gif" /></font></b></td> 		 		 		 		 		 		 		<td align="center" class="border-bluegray-vdelimiter border-bluegray-plrb"><b><font class="tableheadtext">
	.doc <img width="18" height="18" src="/images/icons/word_doc.gif" /></font></b></td> 		<td align="center" class="border-bluegray-plb"><font class="tableheadtext"><b>
	.zip <img width="18" height="18" src="/images/icons/zip_doc.gif" /></b></font></td> 		<td class="border-bluegray-r-line"></td> 	</tr>
   	 	 
    <tr> 		<td class="border-bluegray-l-line border-bluegray-hdelimiter"></td> 		<td class="border-bluegray-vdelimiter border-bluegray-hdelimiter border-bluegray-prt"><b>
	Integration Manual</b> 
        <br />

       <font class="smalltext"><i>(version 8.xx of 11/27/2009)</i></font></td> 		<td align="center" class="border-bluegray-vdelimiter border-bluegray-hdelimiter border-bluegray-plrt"><font class="text"><a href="/download/manuals/en/integration_guide_en.pdf" title="download">
	1,33M</a></font></td> 		 		 		 		 		 		 		<td align="center" class="border-bluegray-vdelimiter border-bluegray-hdelimiter border-bluegray-plrt"><font class="text"><a href="/download/manuals/en/integration_guide_en.doc" title="download">
	1,33M</a></font></td> 		<td align="center" class="border-bluegray-hdelimiter border-bluegray-plt"><center> 
          <div align="center"><font class="text"><a href="/download/manuals/en/integration_guide_en.zip" title="download">
		1,11M</a></font></div>
         </center></td> 		<td class="border-bluegray-r-line border-bluegray-hdelimiter"></td> 	</tr>
   	 
    <tr class="border-bluegray-foot"> 		<td class="border-bluegray-round-bl"></td> 		<td class="border-bluegray-b-line border-bluegray-vdelimiter"></td> 		<td width="15%" class="border-bluegray-b-line border-bluegray-vdelimiter"></td> 		 		 		 		 		 		 		<td width="15%" class="border-bluegray-b-line border-bluegray-vdelimiter"></td> 		<td width="15%" class="border-bluegray-b-line"></td> 		<td class="border-bluegray-round-br"></td> 	</tr>

   </tbody>
</table>
<br/>
<?php
}
}
?> 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/199380-error-joining-3-tables-php-mysql/
Share on other sites

SELECT DISTINCT ALL??? Seriously?

 

That's pretty much your problem right there... you can't query for EVERY bit of data there is.. JOINed or not and expect it to layout the way you want.

 

Which fields do you REALLY need?

To me.. it looks like you only need the title name, it's creation date and whatever links it has.. am I correct?

SELECT cat.cat_title, maglink.file_type, maglink.link
FROM magazine  
LEFT join magazine_links maglink ON maglink.magazine_id = magazine.id
LEFT join magazine_category cat ON cat.magazine_id = magazine.id
WHERE magazine.id = {$_GET['employ_id']}

something like that might work

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.