PHP-MySQL getting data from multiple tables

I have a problem. I can’t solve it. I am not good in PHP-MySQL.

I have three tables.

First Table : linkss --> rows: linkid,link,orderlink

Second Table: sublinkss1 --> rows: sublink1id,sublink1,ordersublink1,link,linkid

Third table : sublinkss2 --> rows: sublink2id,sublink2,ordersublink2,sublink1,sublink1id

[php]
$get_data=mysql_query(“select linkss.link, sublinkss1.sublink1, sublinkss2.sublink2 from linkss,sublinkss1, sublinkss2 where sublinkss1.linkid=linkss.linkid and sublinkss2.sublink1id=sublinkss1.sublink1id order by orderlink, ordersublink1, ordersublink2”);

 while ($row=mysql_fetch_assoc($get_data)) {
    
    $data[$row["link"]][$row["sublink1"]][$row["sublink2"]]=array($row["link"],$row["sublink1"],$row["sublink2"]);
    
    }



    $smarty = new Smarty();
    
    $smarty->assign('data',$data);

[/php]
and tpl file is this

[php]<ul>
{foreach key=link from=$data item=linkss}
<li><a href="#">{$link}</a>
<ul>
{foreach key=sublink1 item=sublinkss1 from=$linkss }
<li><a href="#">
{$sublink1}
</a>

<ul>
{foreach key=sublink2 item=sublinkss2 from=$sublinkss1 }
<li><a href="#">
{$sublink2}
</a>

</li>
{/foreach}
</ul>

</li>
{/foreach}
</ul>

</li>
{/foreach}
</ul>

[/php]
For example some datas are stored in the database and I want output like this

  • Home Page
    • Projects
  • About Us
    • History
    • Products
      • Product1
      • Product2
      • Product3
  • Contact Us

But these codes are not working properly. I tried to use inner join and left join but I couldn’t handle it. Could you help me please. Thanks in advance

this query will select 3 different columns from 3 different table

SELECT table1.NAME
,table2.PRODNAME
,table3.users
FROM table1,table2,table3

this is not what I want. I want something such as category tree with php and mysql

thank you so much for your reply…

Sponsor our Newsletter | Privacy Policy | Terms of Service