Jump to content


Photo

Mixing results from 2 tables


  • Please log in to reply
1 reply to this topic

#1 error_22

error_22
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 October 2006 - 12:15 AM

Hi,

I have a db table called "catlinks". There are three different columns in there (c_id, c_name, c_url). I also have another table called "sublinks" with the columns: s_id, s_name, s_url, s_cat.

I want the values from these tables to show up like this:

<table>
<tr>
<td>Head links</td><td>Sublinks</td>
</tr>
<tr>
<td>headlink#1 (c_name)</td>sublink#1, sublink#2 (s_name with the c_cat value of c_id)</td>
</tr>
<tr>
<td>headlink#2 (c_name)</td>sublink#3, sublink#4 (s_name with the s_cat value of c_id)</td>
</tr>
etc...
</table>

So I tried the following:

echo "<table>";
$sql = "SELECT * FROM catlinks l LEFT JOIN sublinks s ON c_id=s_cat ORDER BY c_name, s.s_name";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_object($result))
{
<tr>
<td><? echo $row->c_name; ?></td>
<td><? echo $row->s_name; ?></td>
</tr>
}
echo "</table>";

The problem is, when I echo the results, I get this:

Posted Image

Any help would be greatly appreciated!

Thanks in advance
Niklas

#2 error_22

error_22
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 October 2006 - 07:33 PM

Anyone?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users