ricky spires Posted March 16, 2012 Share Posted March 16, 2012 hello how would i write, if $a has 1 or more of $b do something ? for example if($a >1 $b){ do something }else{ do nothing } or >2 or >3 etc... thanks Quote Link to comment https://forums.phpfreaks.com/topic/259043-how-would-i-write-if-a-has-1or-more-of-b-do-something/ Share on other sites More sharing options...
kicken Posted March 16, 2012 Share Posted March 16, 2012 What are $a and $b for example? That will likely determine what function you'd use. Quote Link to comment https://forums.phpfreaks.com/topic/259043-how-would-i-write-if-a-has-1or-more-of-b-do-something/#findComment-1327982 Share on other sites More sharing options...
q11we Posted March 16, 2012 Share Posted March 16, 2012 What is datatype of $a and $b. If they are integer or double use if($a >= 2*$b) { //2 or more of $b //start moving } but if they are string you can use preg_match() $reg = "/(".$b."){2,}/"; if(preg_match($reg, $a)) { //two or more //start moving } Quote Link to comment https://forums.phpfreaks.com/topic/259043-how-would-i-write-if-a-has-1or-more-of-b-do-something/#findComment-1327984 Share on other sites More sharing options...
ricky spires Posted March 16, 2012 Author Share Posted March 16, 2012 im trying to say if $id has 1 or more $other_var with the same value as $id do something for example $id - $name - $parent_id 1 - title1 - 0 (parent) 2 - title2 - 0 (parent) 3 - link1 - 1 (child) 4 - link2 - 1 (child) 5 - link3 - 2 (child) 6 - link4 - 2 (child) 7 - link5 - 0 (just a link) 8 - link6 - 0 (just a link) so the above would be if $id has 1 or more $parent_id with the same id do something. i cant use if $id == $parent_id for this. its no good because im trying to set a nested level ------------------------------------------------ this is the actual code with the problem... the part that says "****THIS IS WHERE IM STUCK***" is where i need to put some code that says "if $id HAS ANY $parent_id with the same number make the li a title." <div> $header = Text::find_by_parentID(0); foreach ($header as $headers){ $Hid = $headers->id; $Hname = $headers->name; $Hparent = $headers->parent; echo $Hparent == 0 ? '<h3 class="header">'.$Hname.'</h3>' : ''; echo' <ul class="nav">'; //FIND NESTED TITLES / LINKS $headText = Text::find_by_child($Hid); foreach ($headText as $headTexts){ $Cid = $headTexts->id; $Cname = $headTexts->name; $Cparent = $headTexts->parent; echo ***THIS IS WHERE IS WANT THE CODE*** ? '<li><a href="">'.Cname.'</a></li>' : '<li><a href="" class="subTitle">'.Cname.'</a>'; echo' <ul class="subLevel" style="margin-left: 15px">'; //FIND SUBLINK $sub = Text::find_by_child($Cid); foreach ($subs $subs){ $name = $subs->name; echo'<li><a href="">'.$name.'</a></li>'; } echo' </ul> </li>'; } echo'</ul>'; } echo'</div>'; ?> so im trying to say if a <li> has and sub links the <li> that the $parent_id is pointing to becomes a title Quote Link to comment https://forums.phpfreaks.com/topic/259043-how-would-i-write-if-a-has-1or-more-of-b-do-something/#findComment-1327986 Share on other sites More sharing options...
ricky spires Posted March 16, 2012 Author Share Posted March 16, 2012 hi all. no worries. i fixed it another way.. i add a column in the db called type.. so each item in the list could be set to title or link. that way the header for each nested levels could be set to "title" <?PHP require_once("includes/initialize.php"); ?> <?PHP echo' <div class="arrowlistmenu">'; $nav = PhLists::navOrder($PHLlno, $PHLorb, $PHLord); //FIND HEADER $navHead = PhLists::find_by_parentID(0); foreach($navHead as $navHeads){ $headID = $navHeads->id; $headLnk = $navHeads->pageLink_id; $PCBhead = PCbridge::find_NavText($headLnk, $langID); foreach ($PCBhead as $PCBheads){ $headText = $PCBheads->pageContent_id; $headText = PageContent::find_text($headText); foreach ($headText as $headTexts){ $header = $headTexts->title; echo $navPnt == 0 ? '<h3 class="menuheader expandable">'.$header.'</h3>' : ''; echo' <ul class="categoryitems">'; //FIND LINK & TITLES $navLink = PhLists::find_by_child($headID); foreach($navLink as $navLinks){ $nLid = $navLinks->id; $nLink = $navLinks->pageLink_id; $nLinkPnt = $navLinks->parent_id; $nLinklvl = $navLinks->level; $PCBlink = PCbridge::find_NavText($nLink, $langID); foreach ($PCBlink as $PCBlinks){ $linkText = $PCBlinks->pageContent_id; $lnkText = PageContent::find_text($linkText); foreach ($lnkText as $lnkTexts){ echo $nLinklvl == "Link" ? '<li><a href="">'.$lnkTexts->title.'</a></li>' : '<li><a href="" class="subexpandable">'.$lnkTexts->title.'</a>'; echo' <ul class="subcategoryitems" style="margin-left: 15px">'; //FIND SUBNAV SUBLINK $subNav = PhLists::find_by_child($nLid); foreach($subNav as $subNavs){ $sLinkID = $subNavs->pageLink_id; $sLinkPnt = $subNavs->parent_id; $sLinklvl = $navLinks->level; $PCBsubLink = PCbridge::find_NavText($sLinkID, $langID); foreach ($PCBsubLink as $PCBsubLinks){ $subLinkText = $PCBsubLinks->pageContent_id; $subLnkText = PageContent::find_text($subLinkText); foreach ($subLnkText as $subLnkTexts){ $subLink = $subLnkTexts->title; echo' <li><a href="">'.$subLink.'</a></li>'; }}} echo' </ul> </li>'; }}} echo'</ul>'; }}} echo'</div>'; ?> that did the trick. not what i wanted really but it works - title1 - subTitle1 - subLink1 - link1 - title2 - subTitle2 - subLink2 - link2 thanks Quote Link to comment https://forums.phpfreaks.com/topic/259043-how-would-i-write-if-a-has-1or-more-of-b-do-something/#findComment-1328000 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.