Ruddy Posted February 27, 2012 Share Posted February 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/ Share on other sites More sharing options...
requinix Posted February 27, 2012 Share Posted February 27, 2012 Well, I can reduce that big if block into two conditions to check and a bit of math, but I have no idea what you're asking for. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321853 Share on other sites More sharing options...
Ruddy Posted February 27, 2012 Author Share Posted February 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321857 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 Can anyone else help with this please? Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321869 Share on other sites More sharing options...
requinix Posted February 28, 2012 Share Posted February 28, 2012 Can anyone else help with this please? Oh. Sorry about not getting around to this within the 35 minutes you had allotted me, but I'm sure somebody else knows what I was thinking of doing. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321877 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321881 Share on other sites More sharing options...
ManiacDan Posted February 28, 2012 Share Posted February 28, 2012 "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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321896 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321898 Share on other sites More sharing options...
ManiacDan Posted February 28, 2012 Share Posted February 28, 2012 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' Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321899 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 $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 Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321901 Share on other sites More sharing options...
blacknight Posted February 28, 2012 Share Posted February 28, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321920 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 Erm, its not what I want but If has now givin me an idea. So it has helped. Thanks for the reply, keep up the good work! Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321932 Share on other sites More sharing options...
l0gic Posted February 28, 2012 Share Posted February 28, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1321973 Share on other sites More sharing options...
ManiacDan Posted February 28, 2012 Share Posted February 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1322008 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Author Share Posted February 28, 2012 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!! Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1322018 Share on other sites More sharing options...
ManiacDan Posted February 28, 2012 Share Posted February 28, 2012 Ah-ha. The inside of your loop can still be condensed to 4-5 lines without this big chain of if/elseif. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1322025 Share on other sites More sharing options...
l0gic Posted February 28, 2012 Share Posted February 28, 2012 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!! 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. Quote Link to comment https://forums.phpfreaks.com/topic/257892-running-2-values-in-one-if-statement/#findComment-1322093 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.