parent id child id datebase to php [on hold]











up vote
-1
down vote

favorite












Hello i'm working on this all day today and i'm actually really lost i have a table like this at the moment.



id | category | parent_id



id=5 category=Laptop parent_id=0

id=7 category=Houses parent_id=0

id=8 category=HP parent_id=5

id=9 category=Lenovo parent_id=5



so what i'm trying to do is get this as a category sub category style something like;





  • Laptop




    • HP

    • Lenovo



  • Houses


until know what i have;



            <?php
include_once("dir/db.php");
$result = $db->query("SELECT * FROM categories WHERE parent_id = 0");
?>
<ul>
<?php
while($row = $result->fetch(PDO::FETCH_ASSOC)):
?>
<a href="gallerycato.php?id=<?php echo $row['id']?>"><li><?php echo $row['category'] ?></li></a>

<?php endwhile;?>
</ul>


output;



<ul>
<a href="gallerycato.php?id=5"><li>Laptops</li></a>

<a href="gallerycato.php?id=7"><li>Houses</li></a>

</ul>


but i'm trying to get my Lenovo and HP under Laptop i'd be really happy if you can help me! Thanks.










share|improve this question







New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mathias Ettinger
    2 days ago















up vote
-1
down vote

favorite












Hello i'm working on this all day today and i'm actually really lost i have a table like this at the moment.



id | category | parent_id



id=5 category=Laptop parent_id=0

id=7 category=Houses parent_id=0

id=8 category=HP parent_id=5

id=9 category=Lenovo parent_id=5



so what i'm trying to do is get this as a category sub category style something like;





  • Laptop




    • HP

    • Lenovo



  • Houses


until know what i have;



            <?php
include_once("dir/db.php");
$result = $db->query("SELECT * FROM categories WHERE parent_id = 0");
?>
<ul>
<?php
while($row = $result->fetch(PDO::FETCH_ASSOC)):
?>
<a href="gallerycato.php?id=<?php echo $row['id']?>"><li><?php echo $row['category'] ?></li></a>

<?php endwhile;?>
</ul>


output;



<ul>
<a href="gallerycato.php?id=5"><li>Laptops</li></a>

<a href="gallerycato.php?id=7"><li>Houses</li></a>

</ul>


but i'm trying to get my Lenovo and HP under Laptop i'd be really happy if you can help me! Thanks.










share|improve this question







New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mathias Ettinger
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Hello i'm working on this all day today and i'm actually really lost i have a table like this at the moment.



id | category | parent_id



id=5 category=Laptop parent_id=0

id=7 category=Houses parent_id=0

id=8 category=HP parent_id=5

id=9 category=Lenovo parent_id=5



so what i'm trying to do is get this as a category sub category style something like;





  • Laptop




    • HP

    • Lenovo



  • Houses


until know what i have;



            <?php
include_once("dir/db.php");
$result = $db->query("SELECT * FROM categories WHERE parent_id = 0");
?>
<ul>
<?php
while($row = $result->fetch(PDO::FETCH_ASSOC)):
?>
<a href="gallerycato.php?id=<?php echo $row['id']?>"><li><?php echo $row['category'] ?></li></a>

<?php endwhile;?>
</ul>


output;



<ul>
<a href="gallerycato.php?id=5"><li>Laptops</li></a>

<a href="gallerycato.php?id=7"><li>Houses</li></a>

</ul>


but i'm trying to get my Lenovo and HP under Laptop i'd be really happy if you can help me! Thanks.










share|improve this question







New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Hello i'm working on this all day today and i'm actually really lost i have a table like this at the moment.



id | category | parent_id



id=5 category=Laptop parent_id=0

id=7 category=Houses parent_id=0

id=8 category=HP parent_id=5

id=9 category=Lenovo parent_id=5



so what i'm trying to do is get this as a category sub category style something like;





  • Laptop




    • HP

    • Lenovo



  • Houses


until know what i have;



            <?php
include_once("dir/db.php");
$result = $db->query("SELECT * FROM categories WHERE parent_id = 0");
?>
<ul>
<?php
while($row = $result->fetch(PDO::FETCH_ASSOC)):
?>
<a href="gallerycato.php?id=<?php echo $row['id']?>"><li><?php echo $row['category'] ?></li></a>

<?php endwhile;?>
</ul>


output;



<ul>
<a href="gallerycato.php?id=5"><li>Laptops</li></a>

<a href="gallerycato.php?id=7"><li>Houses</li></a>

</ul>


but i'm trying to get my Lenovo and HP under Laptop i'd be really happy if you can help me! Thanks.







php pdo






share|improve this question







New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Andrew

1




1




New contributor




Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Andrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Your Common Sense, Mast, Mathias Ettinger, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.












  • I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mathias Ettinger
    2 days ago


















  • I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mathias Ettinger
    2 days ago
















I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Mathias Ettinger
2 days ago




I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Mathias Ettinger
2 days ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Morgemoulin

Scott Moir

Souastre