Jump to content

Running 2 values in one IF statement


Ruddy

Recommended Posts

What I want to do is run both '$intel_mod' and '$op_intel_mod' in that if statement and output 2 different variables for both of them.

 

e.g:

So '$intel_mod' goes in and comes out as '$int_mod = 0.85'

Then '$op_intel_mod' should go in and come out as '$op_int_mod'.

 

Somthing like that is what im after, im now thinking this is not the way to do it or I should be using a loop?

 

	

	$intel_mod = $user_int/$op_int;
	$op_intel_mod = $op_int/$user_int;

	if($intel_mod < 0.20) {
		$int_mod = 0.75;
	}
	elseif($intel_mod < 0.40){
		$int_mod = 0.80;
	}
	elseif($intel_mod < 0.60){
		$int_mod = 0.85;
	}
	elseif($intel_mod < 0.80){
		$int_mod = 0.90;
	}
	elseif($intel_mod < 0.1){
		$int_mod = 0.95;
	}
	elseif($intel_mod == 1){
		$int_mod = 1;
	}
	elseif($intel_mod > 2){
		$int_mod = 1.10;
	}
	elseif($intel_mod > 3){
		$int_mod = 1.20;
	}
	elseif($intel_mod > 4){
		$int_mod = 1.30;
	}
	elseif($intel_mod > 5){
		$int_mod = 1.40;
	}
	elseif($intel_mod > 0.20){
		$int_mod = 1.50;
	}

 

Any help would be great,

Ruddy

Link to comment
Share on other sites

erm, I think that would work.

 

If kinda like finding a grade for a student. But I need to do it for mulitplie grades in 1 go.

 

Does that make any sense? But i think what you said would work if you could do that would be great. Comments to teach me why you did what would also be amazing.

Link to comment
Share on other sites

Don't think you need to be rude, and I didnt ask anyone to do what you was going to go. Was asking if anyone else knew how to do what I want.

 

I didnt tell you to do it I asked if you could would be great (it would), I just was trying to do it ASAP as once I start I dont like to stop.

 

If you could help would be great.

 

Cheers,

Ruddy.

Link to comment
Share on other sites

"Bumping" your threads is actually against the rules of the forum.

 

Explain the logic you're trying to implement here.  Like Requinix, I think I can condense this to a couple of lines, but you have a random rule that breaks the pattern.  Why does this block appear?

 

		elseif($intel_mod < 0.1){
		$int_mod = 0.95;
	}

 

Regardless, it's  in the wrong spot, as is this one:

 

		elseif($intel_mod > 0.20){
		$int_mod = 1.50;
	}

 

Explain the "rule" you're trying to implement, and don't bump.

Link to comment
Share on other sites

Sorry for the bump then, and forget that code.

 

Like I said before its kinda like finding a grade for a student. But I need to do it for mulitplie grades in 1 go.

 

So if students mark is "90" it runs through a statement that finds if thats a A,B,C,D and so on. But I want to do it for multiplle "grades". So I want to run thr mark "90" and the mark "80" right after.

 

So in 1 click of "find grade" button it will grab them 2 values run them through and output a grade for each.

 

I hope that makes sense.

Link to comment
Share on other sites

Nope, sorry, doesn't make sense.

 

Show some starting inputs and their desired outputs.  Right now you have some kind of calculation that appears to follow a pattern (except for the 2 examples I cited) but does random division beforehand and only works on one of the two variables you keep calling 'grades' but are named 'mod'

Link to comment
Share on other sites


$value1 = 0.10 //Want this one to run into that IF to find the "$result"
$value2 = 0.30 //Then this one to go in


	if([$value1 and $value2] < 0.20) {
		$result= 0.75;
	}
	elseif([$value1 and $value2] < 0.40){
		$result= 0.80;
	}

echo $result; //for $value1

echo $result; //for $value2

 

I know that dont make that much sense, but I want to find the $result of $value1 and output it as its own variable and the same with $value2.

 

Hope that makes sense xD

Link to comment
Share on other sites

i think i under stand try and fallow my example

 

you ahve 5 people with grades

john - 80

bob  - 75

mike - 88

jan - 65

tom - 25

you want to run them throu the function to assign something like a gpa average based on a decimal system you are using?

if so..

you need to make the marks an array and pass them through the function using a for statement

 

ex

$results=array();
foreach($marks as $student => $mark)
{
      $results[$sutdent] = gpamark($mark);
} 

then printing $results should have your numbers..

 

marks should appear like this

$marks = array('john' => '80','bob' => '75','mike' => '88','jan' => '65','tom' => '25');

 

hope that helps a lil...

Link to comment
Share on other sites

Shouldn't be too hard!

 

Try:

<?php
// Create an array containing the score values you want to run

$score = array(0.10, 0.30);

// Great, that's an array! We could call any of the array values by using
// $score[*] where * is its place in the array.

// So...
// $score[0] = 0.10
// $score[1] = 0.30

// Now we want to loop through this array and modify the
// current score, turn it into your result and echo it

$i=0;                                 // Set out loop count to 0.
while($i < count($score)) {           // While our loop count is less then the number of values in the array, loop!
  if($score[$i] < 0.20) {             // If $score[$i] (the first array value) is less than 0.20 then..
    $score[$i] = 0.75;                // ..set $score[$i] to the desired result (in this case 0.75)
  }else if($score[$i] < 0.40) {       // Else if it's less than 0.40..
    $score[$i]= 0.80;                 // ..set $score[$i] to the desired result (in this case 0.80)
  }
  echo $score[$i]."<br>";             // Echo $score[$i] and a line break.
  $i++;                               // Increment our loop count by one.
}
?>

 

That'll output:

0.75
0.8

 

You can add more 'scores' by adding them into the array at the start, example:

<?php
...
$score = array(0.10, 0.30, 0.13, 0.16, 0.25, 0.33);
...
?>

 

And you can add more 'results' by adding more else ifs, example:

<?php
...
  else if($score[$i] < 0.40) {
    $score[$i]= 0.80;
  }else if($score[$i] < 0.60) {
    $score[$i]= 0.85;
  }else if($score[$i] < 0.80) {
    $score[$i]= 0.90;
  }
...
?>

 

Hope that helps?

Link to comment
Share on other sites

No, sorry, you're still not making any sense at all.  Explain it to me like I don't know what you're saying (which clearly none of us do).  Look at your comments here:

 

$value1 = 0.10 //Want this one to run into that IF to find the "$result"

$value2 = 0.30 //Then this one to go in

 

You want to run into a an if and then the other one to go in?  What?

 

Also, you echo one result twice, I don't know how you think they'll be different numbers.

Link to comment
Share on other sites

l0gic you are a god! Thank you so much, used your code line for line!

 

Also to everyone else, thats what I was trying to do!! :D

 

Thanks again.

 

Far from a God fella, I learnt a lot about PHP from the guys on these forums. And this method was kind of already mentioned earlier in the thread but I was just the first to put it into working code.. But you're wlecome.

 

Ah-ha.

 

The inside of your loop can still be condensed to 4-5 lines without this big chain of if/elseif.

 

I was thinking about doing that, but tried to make it as simple to understand as I could. I'm pretty sure a more experienced hand could shrink it down to about five or six lines though, depending on how many results he wants to add.

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.