Welcome Guest, Not a member yet? Register   Sign In
Function for exact range
#1

[eluser]Fantass[/eluser]
Hello, heres the trouble if i want a exact range for example 1-10 do specific function

this way
Code:
<?php

$input= 1; //

if ($input == 1):
echo 'OK';
elseif($input == 2):
echo 'OK';
elseif($input == 3):
echo 'OK';
elseif($input == 4):
echo 'OK';
elseif($input == 5):
echo 'OK';
elseif($input == 6):
echo 'OK';
elseif($input == 7):
echo 'OK';
elseif($input == 8):
echo 'OK';
elseif($input == 9):
echo 'OK';
elseif($input == 10):
echo 'OK';
endif;?>

But the real trouble is i had to do arround 2 thousand if's by this way, theres another way to do this specifing Example range 20-31 do this.. etc,? Thanks alot.
#2

[eluser]CroNiX[/eluser]
Code:
if ($input >= 20 AND $input <= 31) echo 'OK';
#3

[eluser]pbflash[/eluser]
Code:
if ($input >= 1 && $input <= 10)
{
  do something
}
else
{
  do something else
}
#4

[eluser]Fantass[/eluser]
Thanks brous! Smile
#5

[eluser]Fantass[/eluser]
[quote author="CroNiX" date="1330063315"]
Code:
if ($input >= 20 AND $input <= 31) echo 'OK';
[/quote]
[quote author="pbflash" date="1330063452"]
Code:
if ($input >= 1 && $input <= 10)
{
  do something
}
else
{
  do something else
}
[/quote]

Thank yo guys now can yo help me how do this query into MySql?

THANKS ALOOOOOOOT
#6

[eluser]PhilTem[/eluser]
How do you want to put it into MySQL? Make the query take care of this check like select only rows if some column's value is within that range?

Have a look at http://dev.mysql.com/doc/refman/5.0/en/i...ement.html and http://www.java2s.com/Code/SQL/Flow-Cont...clause.htm for an example.

Quick and dirty example:
Code:
SELECT name AS Name, category AS Category,
    IF( winter > 500, "Sells", "Slow") AS Trend
    FROM sales;
#7

[eluser]CroNiX[/eluser]
Selecting Ranges:
Code:
SELECT fields FROM table WHERE field >= 20 AND field <= 31
or
Code:
SELECT fields FROM table WHERE field BETWEEN 20 AND 31
#8

[eluser]Aken[/eluser]
No offense here, but if you are running loops like THAT, you might want to stay away from CodeIgniter until you get a bit more familiar with PHP. You may be in over your head very quickly.
#9

[eluser]Fantass[/eluser]
[quote author="Aken" date="1330327632"]No offense here, but if you are running loops like THAT, you might want to stay away from CodeIgniter until you get a bit more familiar with PHP. You may be in over your head very quickly.[/quote]
Eventually.




Theme © iAndrew 2016 - Forum software by © MyBB