Jump to content

Mixing results from 2 tables


error_22

Recommended Posts

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:

[code]
<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>
[/code]

So I tried the following:

[code]
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>";
[/code]

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

[img]http://www.octocomnetwork.com/result.png[/img]

Any help would be greatly appreciated!

Thanks in advance
Niklas
Link to comment
Share on other sites

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.