I have a simple PHP Array called $gatherArr that looks like this:
$gatherArr = [
["catCode"=>"ac", "catName"=>"Armchair"],
["catCode"=>"sf", "catName"=>"Sofa"],
["catCode"=>"st", "catName"=>"Side Table"],
["catCode"=>"ct", "catName"=>"Coffee Table"],
["catCode"=>"dt", "catName"=>"Table"],
["catCode"=>"cs", "catName"=>"Chair / Stool"],
["catCode"=>"sb", "catName"=>"Side Board"],
];
I want to build a Menu bar with PHP code and get the dropdown list from the $gatherArr. This is my HTML code below.
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">About</li>
<li>News</li>
<li class="dropdown">
Collection <b class="caret"></b>
<ul class="dropdown-menu">
<?php
include './productData.php';
foreach ($gatherArr as $name => $detail) {
echo" {$detail}<br />";
}
?>
</ul>
</li>
<li>Ordering</li>
<li>Contact</li>
</ul>
</div>
I get lines of errors in displaying in the drop down menu bar. I have also tried change the echo" {$detail}<br />"; To $name but I got numbers from 0 - 6 in the menu bar
Thanks!
{$detail}
is array, You can't print or echo arrays. You can, however, print a specific element of it like:
{$detail['catCode']}
or
{$detail['catName']}
Related
i am literally stuck with getting these ul/li elements in one row.
Only first li has class, others are in another ul but without class or id. i tried multiple searches and loops, but can't get it right.
Below results returns too many rows where elements don't fit together.
Can someone help me?
idealy the result from below example would be:
'part', 'desc', 'qty'
'106128-001','LBL, BLNK,THERMAL PRINT','1'
'106128-004','LBL, BLNK THERMAL,RECT 2.40x4','1'
HTML example
<div id='tab1' class="section tab" data-position="auto" style="max-height:none;">
<ul class="links">
<li id="innertab1">106128-001</li>
</ul>
<ul id="combom0" class="tab1 cols2 compare">
<li style="border: none;">
<div>
<ul>
<li><strong>Description: </strong>LBL, BLNK,THERMAL PRINT</li>
<li><strong>Qty: </strong>1</li>
</ul>
</div>
</li>
</ul>
<ul class="links">
<li id="innertab1">106128-004</li>
</ul>
<ul id="combom1" class="tab1 cols2 compare">
<li style="border: none;">
<div>
<ul>
<li><strong>Description: </strong>LBL, BLNK THERMAL,RECT 2.40x4</li>
<li><strong>Qty: </strong>1</li>
</ul>
</div>
</li>
</ul>
My poor attempt with trying to count rows:
$search = $html->find('div[id=tab1]',0);
$i=0;
$alles=array();
foreach ($search->find('* li') as $test){
if(!empty($test->innertext)){
if($i>3){$i=0;}
$i++;
if($i==1){
echo $alles_li['part'] = strip_tags($test->innertext);
}
if($i==2){
// don't need this, bad stripping
strip_tags($test->innertext);
}
if($i==3){
$alles_li['desc'] = strip_tags($test->innertext);
}
if($i==4){
$alles_li['qty'] = strip_tags($test->innertext);
}
}
// if less than 3 elements don't add
if(count($alles_li)==3){
$alles[]=$alles_li;
}
}
How can I create a function to scan all menu items from Drupal 7 system and if there is a nested ul, add dropdown CSS classes to the nested ul and add a custom attribute to the parent li container? Im using UIKIT which will automatically create the dropdowns.
Here's my current menu HTML output:
<ul class="menu">
<li class="first last expanded">
<a title="" href="/node/add">Add content</a>
<ul class="menu">
<li class="first leaf">
<a title="article" href="/node/add/article">Article</a></li>
<li class="leaf">
<a title="page" href="/node/add/page">Basic page</a></li>
<li class="last leaf"><a title="blog" href="/node/add/blog">Blog entry</a></li>
</ul>
</li>
</ul>
Here's what I need it to be:
<ul class="menu">
<li class="first last expanded" data-uk-dropdown>
<a title="" href="/node/add">Add content</a>
<ul class="menu uk-dropdown">
<li class="first leaf">
<a title="article" href="/node/add/article">Article</a></li>
<li class="leaf">
<a title="page" href="/node/add/page">Basic page</a></li>
<li class="last leaf"><a title="blog" href="/node/add/blog">Blog entry</a></li>
</ul>
</li>
</ul>
Im looking for the simplest approach possible.
You can crawl menu tree your self and write out menu HTML as you like. Used that and should be something like:
$tree = menu_tree_all_data('menu_machine_name');
Also, if I remember well, if you do only that your active (current) menu item won't be marked any way, and for marking it you have to also call (after getting $tree variable) :
menu_tree_add_active_path($tree);
But again, if I remember well, that function is only available if you install "Menu block" module...
Print out $tree variable after that and organize your code to crawl recursively menu tree you collected.
i ve done this below menu in php which is autogenerated with a function :
As you know, if i click on "Red Chicken", it will try to open a ../Red%20Chicken URL, which doesnt exist till it comes from a big table which change everytime.
What i want to do is : to know where we clicked (example : by generating the url and cut it ) and then redirect to a page like result.php (+ get something like the variable to know where do we come from). And of course, i don't want to create a .php page for each element of my table.
Is this thing possible ?
EDIT : i found a way, it's to change my function and how it generates the menu.
Not really what i wanted but it's okay.
<ul class=\"niveau1\">
<li class=\"sousmenu\"><a href=\"Food\">Food</li>
<ul class=\"niveau2\">
<li class=\"sousmenu\">Meat</li>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Poultry</li>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Red Chicken</li>
</ul>
</ul>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Beef</li>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Hamburgers</li>
</ul>
<ul class=\"niveau4\">
<li class=\"sousmenu\">Steak</li>
</ul>
</ul>
</ul>
<ul class=\"niveau2\">
<li class=\"sousmenu\">Dairy</li>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Cow</li>
</ul>
<ul class=\"niveau3\">
<li class=\"sousmenu\">Sheep</li>
</ul>
</ul>
</ul>
<ul class=\"niveau1\">
<li class=\"sousmenu\">name</li>
</ul>
http://jsfiddle.net/w10j0a38/1/
The PHP-Way would probably be to use URLs like <a href='menuhandler.php?sel=cow'>Cow</a>, and if you want to be lazy, you could also JS/jquery to manupulate the URLs and replace <a href="something">with a call in the style shown before - but then this would not work w/o JS, so it is not a real option IMHO.
changed my function to generate it in another way
<a href=\"Recette.php?var=food\">
Not really what i wanted but it's okay.
I am trying to display something from my database on a bootstrap bar and I have no idea how to combine or implement the two. Ive made my bootstrap html's file a .php, was that the correct thing to do? Here's my code (ignore the filler words)
<ul class="nav nav-list well">
<li class="nav-header"></li>
<li class="active">HIT INFO</li>
<li>Linky link</li>
<li class="divider"></li>
<li>ANOTHER HIT INFO</li>
<li>ANOTHER LINKY LINK</li>
<li class="divider"></li>
<li>YET ANOTHER HIT</li>
<li>AAAAAnd another link</li>
</ul>
and this is the php i want to include (the code to making what i want to display is in the file)
<?php include 'one.php'; ?>
where "linky link" is, i want to display this but it didnt seem to work when i put that php right there. Another thing i want to do is when a link from the database gets displayed, it displays as a bootstrap button. i tried and am just not sure how to implement php code in my bootstrap code.
Print " <td>".$row['link'] . "</td></tr> ";
How would i add this bootstrap code to that so when a link from my database gets displayed, it gets displayed as this button
<i class="icon-heart icon-white"></i>Do this HIT!
Your code seems right to me except to your "<td> and <tr>" tag. You're not using it right.
Try this approach
In one.php
<?php
$links = array( 0 => array("url"=>"http://google.com","text"=>"Google") );
?>
In Menu
<?php include('one.php')?>
<ul>
<li>Menu one</li>
<?php foreach( $links as $link){ ?>
<li><a href="<?php print $link['url']?>"><?php print $link['text']?></li>
<?php } ?>
</ul>
<?php $activesidebar[$currentsidebar]="id=isactive";?>
<div class="span3">
<div class="well sidebar-nav hidden-phone">
<ul class="nav nav-list">
<li class="nav-header" <?php echo $activesidebar[1] ?>>Marketing Services</li>
<li>Marketing Technology</li>
<li>Generate More Sales</li>
<li>Direct Email Marketing</li>
<li class="nav-header" <?php echo $activesidebar[2] ?>>Advertising Services</li>
<li>Traditional Medias</li>
<li>Online & Social Medias</li>
<li>Media Planing & Purchasing</li>
<li class="nav-header" <?php echo $activesidebar[3] ?>>Technology Services</li>
<li>Managed Websites</li>
<li>Managed Web Servers</li>
<li>Managed Databases</li>
<li class="nav-header" <?php echo $activesidebar[4] ?>>About Us</li>
<li>Contact Us</li>
</ul>
</div>
This is added to the current page I want to add this on.
<?php $currentsidebar =2; include('module-sidebar-navigation.php');?>
I had programmed this menu individually on each page, but to make my website dynamic I used one file and use php includes to load the file. I can get the menu to highlight on the current page assigning an id="isactive", how can I assign id="notactive" to the other 3 menu items that are not active on that page. Is there an else or elseif I have to include?
Reset the array before setting your preferred index.
for ($i = 0; $i < 4; $i++) {
$activesidebar[$i] = "class=\"noactive\"";
}
Notes:
PHP array indices start from 0, not 1.
ID's are meant to be unique (ie, there cannot be 2 of the same ID). Use a classname instade.