Jump to content

[SOLVED] Selecting a variable using if "greater than"??


Mike088

Recommended Posts

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 :)

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? :)

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  :-\

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.

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);
?>

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 :D

 

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 :P

 

Thanks for the help mate.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.