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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.