ecabrera Posted July 18, 2012 Share Posted July 18, 2012 why do i get a error on <li><a href='#nogo'>$cat['parent']</a></li> echo " <div id='navigation'> <ul id='nav'> <!-- main item 1 --> <li class='item1'> <a href='".strtolower(str_replace(' ', '-', $cat['title'])).".htm'>".str_replace('and', '&', $cat['title'])."</a> <!-- dropdown or flyout 1 --> <ul> <li><a href='#nogo'>$cat['parent']</a></li> </ul> </li> </ul> </div> "; Quote Link to comment Share on other sites More sharing options...
xyph Posted July 18, 2012 Share Posted July 18, 2012 You need to surround associative array calls in curly braces, when using the double-quote string syntax. echo "This is {$array['how']} you do it"; http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing Quote Link to comment Share on other sites More sharing options...
ecabrera Posted July 18, 2012 Author Share Posted July 18, 2012 thanks ok so i want the nav to be like Tech -> Video Games -> Computers - > Mouses but only some categories have subcategories i want to do an if statement how would i get around that for example if($cat['parent'] > 0){ <ul> <li><a href='#nogo'>$cat['subparent']</a></li> </ul> }else { } Quote Link to comment Share on other sites More sharing options...
ecabrera Posted July 19, 2012 Author Share Posted July 19, 2012 ok so how would i do this some categories have subcategory not all of them so i want to make it so that the ones that have subcategory show and the ones that dont dont show the categored are listed by id's for now for example 40 34 23 13 53 23 54 34 23 the subcategory have a field name parent which has their parents id for example their are three 40's they should be with category 40 <?php $sql = "SELECT * FROM ".$sitevar['db']['prefix']."categories WHERE parent = 0 ORDER BY title ASC"; $cats = mysql_fetch_all(qrydb($sql)); $newsql = "SELECT * FROM ".$sitevar['db']['prefix']."categories WHERE parent > 0 ORDER BY title ASC"; $subcats = mysql_fetch_all(qrydb($newsql)); foreach ($cats as $cat) foreach ($subcats as $subcat) echo " <div id='navigation'> <ul id='nav'> <!-- main item 1 --> <li class='item1'> <a href='".strtolower(str_replace(' ', '-', $cat['title'])).".htm'>".str_replace('and', '&', $cat['id'])."</a> <!-- dropdown or flyout 1 --> <ul> <li><a href='#nogo'>{$subcat['title']}</a></li> </ul> </li> </ul> </div> "; ?> Quote Link to comment Share on other sites More sharing options...
ecabrera Posted July 19, 2012 Author Share Posted July 19, 2012 is there a way i can add a if statement if the echo Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 No, you have to end the echo. You can do a ternary operation but you should probably stick with ending the echo. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.