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.
php pdo
New contributor
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.
add a comment |
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.
php pdo
New contributor
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
add a comment |
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.
php pdo
New contributor
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
php pdo
New contributor
New contributor
New contributor
asked 2 days ago
Andrew
1
1
New contributor
New contributor
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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