Jump to content


This topic is now archived and is closed to further replies.


Mixing results from 2 tables

Recommended Posts


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:

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

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))
<td><? echo $row->c_name; ?></td>
<td><? echo $row->s_name; ?></td>
echo "</table>";

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


Any help would be greatly appreciated!

Thanks in advance

Share this post

Link to post
Share on other sites


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.