HTML malformed |
Hello again
![]() I am using jsTree plugin to show some data, the code is working but HTML is malformed. Can someone help me to correct this code? The array looks like this: Code: $users = array( Code: <div class="container well" id="tree"> Quote: <ul> I visualize the problem but I don't know where to put the missing parts in the code abow. (Tried some things but then the nodes with more children don't show up) Any help is very appreciated!
Your last echo in the foreach should be like this:
PHP Code: <div class="container well" id="tree"> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks for the answer,
I have tried that but then the second node name ('Sabi') of the CS department does not show up because the HTML looks like this: Quote:<ul>when in fact it should be like this: Quote:<ul>
Code for your view:
PHP Code: <html>
Another solution :
PHP Code: <div class="container well" id="tree">
You can use this code.
<ul> <?php foreach ($users as $key => $value) { ?> <?php if($users[$key]['department'] != $users[$key-1]['department']) { ?> <li><?php echo $users[$key]['department']; ?></li> <ul> <li><?php echo $users[$key]['fullname']; ?></li> </ul> <?php } else { ?> <ul> <li>Sabi</li> </ul> <?php } ?> <?php } ?> </ul>
(12-31-2017, 11:45 PM)XtreemDeveloper Wrote: You can use this code. (12-31-2017, 11:45 PM)XtreemDeveloper Wrote: <?php foreach ($users as $key => $value) { ?> No, you can't. The $key-1 will throw an error at the first iteration of the foreach loop, because $key-1 doesn't exist at that point. Besides that, in your code, every department with more than one user, will have one or more users named "Sabi". |
Welcome Guest, Not a member yet? Register Sign In |