Mike088 Posted October 17, 2008 Share Posted October 17, 2008 Hey all, basically I have a PHP class which details different things and I am wanting to have them all work BUT if the count value of another variable ($results) is greater than 60 then I want it to only run the one variable type. The generated stuff from the class is then output to another variable ($query) $word = trim($_POST["word"]); $entry = array(); $entry = array_merge( $entry, cEntry::getAnswers1($word)); $entry = array_merge( $entry, cEntry::getAnswers2($word)); $entry = array_merge( $entry, cEntry::getAnswers3($word)); $entry = array_merge( $entry, cEntry::getAnswers4($word)); $results = count ($entry); if ($results > 60) $entry = array_merge( $entry, cEntry::getAnswers2($word)); $query = implode (',', $entry); I am having trouble getting it to do so, help would be appreciated thanks Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/ Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 I don't get it. If $results is over 60, you only want to run $entry = array_merge( $entry, cEntry::getAnswers2($word)); ? Meaning you won't run $entry = array_merge( $entry, cEntry::getAnswers1($word)); $entry = array_merge( $entry, cEntry::getAnswers2($word)); $entry = array_merge( $entry, cEntry::getAnswers3($word)); $entry = array_merge( $entry, cEntry::getAnswers4($word)); ? Couldn't be that you mean, since $results would always be zero before one of the above blocks is run. What do you mean? Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667895 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 Ok I guess they will all run originally to get the $results then I want: if the results returned are greater than 60 to maybe re-run it so that it only runs through the $entry = array_merge( $entry, cEntry::getAnswers2($word)); and then outputs that to the $query variable. If you get that lol :-\ Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667897 Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 From what I can see, your code does what you want then. What's not working? When error checking, always make sure that the variables concerned contains what you are expecting. Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667906 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 Well I am using a print command later on for $query and it gives the info from all classes even if the count value is above 60 Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667910 Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 But aren't you running all classes (cEntry::getAnswers1, cEntry::getAnswers2, cEntry::getAnswers3, cEntry::getAnswers4), both when the count is below and above 60? Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667913 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 I want it to run all classes if the count is below 60 and if it is above 60 I only want it to run the Answers2 class, in order to get the count it's running through all classes first tho. I want it to then output either all classes or the answers2 class at the end using my print command of the $query. Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667918 Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 Oh! Easy, just don't merge the Answers2 array with the $entry array, in the "above 60" block: <?php $word = trim($_POST["word"]); $entry = array(); $entry = array_merge( $entry, cEntry::getAnswers1($word)); $entry = array_merge( $entry, cEntry::getAnswers2($word)); $entry = array_merge( $entry, cEntry::getAnswers3($word)); $entry = array_merge( $entry, cEntry::getAnswers4($word)); $results = count ($entry); if ($results > 60) $entry = cEntry::getAnswers2($word); $query = implode (',', $entry); ?> Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667922 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 Oh! Easy, just don't merge the Answers2 array with the $entry array, in the "above 60" block Nah it's still doing the same thing lol Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667925 Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 Sure you changed if ($results > 60) $entry = array_merge( $entry, cEntry::getAnswers2($word)); to if ($results > 60) $entry = cEntry::getAnswers2($word); ? Can't see why it shouldn't work. Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667927 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 positive mate I'll keep slaving away at it, would I have to do anything special with the print command in order to get it to reflect the correct output? (I'm just using print $query; at the end). Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667932 Share on other sites More sharing options...
Mike088 Posted October 17, 2008 Author Share Posted October 17, 2008 OOH I think I have it, just added another counting variable which does a recount and it looks to be working... well the $query variable is containing the correct stuff generated from the 2nd class only I'm pretty beat so I think I'll leave it there for the time being and mark this solved. If it buggers up I'll come re-open it Thanks for the help mate. Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667933 Share on other sites More sharing options...
thebadbad Posted October 17, 2008 Share Posted October 17, 2008 That's good then I was about to post: $entry is first set to contain the output from Answers1-4, and if $entry then contains more than 60 items, $entry is reset to contain only the output from Answers2. Can I see the whole script, the output you expect and the output you get? Link to comment https://forums.phpfreaks.com/topic/128831-solved-selecting-a-variable-using-if-greater-than/#findComment-667934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.