ricky spires Posted April 20, 2012 Share Posted April 20, 2012 Hello. Im having trouble using a Tempory Operator in a list. maybe someone might know a way around it. so the list below has 3 Tempory Operators. the first 1 looks for pages with links that are internal links the first 2 looks for pages with links that are external links the first 3 looks for pages with links that have no links if the link is a "nonTitle" it will be a normal list item if the link is a "title" it will be a header for a sub list (class="subexpandable") the problem is that every time it gets to the '; at the end of each Tempory Operators it breaks THIS IS NOT WORKING <ul> //FIND INTERNAL LINKS echo $type == "internal" && $list == "nonTitle" ? '<li><a href="index.php">'.$title.'</a></li>' : '<li><a href="index.php" class="subexpandable">'.$title.'</a>'; //FIND EXTERNAL LINKS echo $type == "external" && $list == "nonTitle" ? '<li><a href="http://www.url.com">'.$title.'</a></li>' : '<li><a href="http://www.url.com" class="subexpandable">'.$title.'</a>'; //FIND NON LINKS echo $type == "non" && $list == "nonTitle" ? '<li><a>'.$title.'</a></li>' : '<li><a class="subexpandable">'.$title.'</a>'; //GET SUB LINKS echo' <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li> </ul>'; If i put the sub level inside of each type it works but then i keep having to use the same code over. THIS IS WORKING <ul> //FIND INTERNAL LINKS echo $type == "internal" && $list == "nonTitle" ? '<li><a href="index.php">'.$title.'</a></li>' : '<li><a href="index.php" class="subexpandable">'.$title.'</a> <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li>'; //FIND EXTERNAL LINKS echo $type == "external" && $list == "nonTitle" ? '<li><a href="http://www.url.com">'.$title.'</a></li>' : '<li><a href="http://www.url.com" class="subexpandable">'.$title.'</a> <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li>'; //FIND NON LINKS echo $type == "non" && $list == "nonTitle" ? '<li><a>'.$title.'</a></li>' : '<li><a class="subexpandable">'.$title.'</a> <ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li>'; </ul>'; so is there a way to do the first example without having to do the second example thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/261315-lists-problem-with-tempory-operators/ Share on other sites More sharing options...
Drummin Posted April 20, 2012 Share Posted April 20, 2012 Not sure if this is going to work for you, but I'll throw it out there. echo '<ul>' //FIND INTERNAL LINKS .($type == "internal" && $list == "nonTitle" ? '<li><a href="index.php">'.$title.'</a></li>' : '<li><a href="index.php" class="subexpandable">'.$title.'</a>').' //FIND EXTERNAL LINKS '.($type == "external" && $list == "nonTitle" ? '<li><a href="http://www.url.com">'.$title.'</a></li>' : '<li><a href="http://www.url.com" class="subexpandable">'.$title.'</a>').' //FIND NON LINKS '.($type == "non" && $list == "nonTitle" ? '<li><a>'.$title.'</a></li>' : '<li><a class="subexpandable">'.$title.'</a>').' //GET SUB LINKS '.'<ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li> </ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/261315-lists-problem-with-tempory-operators/#findComment-1339156 Share on other sites More sharing options...
Drummin Posted April 20, 2012 Share Posted April 20, 2012 Actually, this looks better. <?php echo '<ul>'; //FIND INTERNAL LINKS echo ($type == "internal" && $list == "nonTitle" ? '<li><a href="index.php">'.$title.'</a></li>' : '<li><a href="index.php" class="subexpandable">'.$title.'</a>'); //FIND EXTERNAL LINKS echo ($type == "external" && $list == "nonTitle" ? '<li><a href="http://www.url.com">'.$title.'</a></li>' : '<li><a href="http://www.url.com" class="subexpandable">'.$title.'</a>'); //FIND NON LINKS echo ($type == "non" && $list == "nonTitle" ? '<li><a>'.$title.'</a></li>' : '<li><a class="subexpandable">'.$title.'</a>'); //GET SUB LINKS echo '<ul class="subcategoryitems" style="margin-left: 15px"> <li><a href="">sub link</a></li> </ul> </li> </ul>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/261315-lists-problem-with-tempory-operators/#findComment-1339168 Share on other sites More sharing options...
requinix Posted April 20, 2012 Share Posted April 20, 2012 Tempory Operator Ternary. It's called the ternary operator. Quote Link to comment https://forums.phpfreaks.com/topic/261315-lists-problem-with-tempory-operators/#findComment-1339175 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.