PHP - If Statement + Numbers In A Range With Decimals
Just looking to know if this is the proper way to implement this:
I need the below if to be true when any number between 100 and 1000 is the value of x, including say "105.55" if($x>= 100 && $x <= 1000){ } Basically I'm asking will a value of x with a decimal in it not cause the if statement to be true. Similar TutorialsSo I already have this below...
$state = array ( Can those numbers be a range -- 1-16, 17-32, 33-48 and 49-64 -- without just listing them all?
Can I somehow mix letters with numbers to create an array with range()? e.g. I want my array for postcode ranges such as array('AB1','AB2', 'AB3', 'AB4', 'AB5', 'Ab6', 'AB7', 'AB8', 'IV5', 'IV6', 'IV7', 'IV8', 'IV9', 'IV10'); I know I can do range(1,8); but was wondering if there was something along the lines of range("AB1", "AB8"); Hi, I have a page on which decimal values are entered. The problem is however that sql does not recognize the comma (the european decimal separator) as the decimal separator. How can I change the input to something that sql can accept? And what if someone enters a number in English format (a dot instead of a comma)? Or uses thousands-separators? Has anyone have experience with this? Greetz, Winelover Hello all it is my 1st post so welcome me i need to make php check if the number is 3 decimals and the last digit is 0. if it is 0 it will echo something if it is not 0 then it will echo something else i came up with this code but i dont know how to make it check if the decimal has a trail of 0 (zero) Code: [Select] <?php if(strpos($Price,".090") !== false){ echo "there is 0 at the end of the price"; //here code to remove the 0 if it is possible }else{ echo "there is no 0 at the end of the price"; // echo the normal price } ?> this will work correctly for the price $4.090 , 12.090 etc but how can i do it in php so it will check if there is 0 at the end of the decimal? Here is the number: $GrandTotal = "68.835"; $Deposit = round($GrandTotal , 2) * .5; echo $Deposit; I am looking for: 68.84 but the function doesn't seem to work right. Any help? Code: [Select] $_POST['amount'] = intval($_POST['amount']); if ($_POST['amount'] < 0){ message($lang_common['Bad request']); } if (!is_numeric($_POST['amount'])){ message($lang_common['Bad request']); } echo $pun_user['gold']; echo '<br>'; echo $_POST['amount']; exit; if I enter 0.05 in my gold input textbox and submit it, it reads 0, it doesn't read the decimal values, i need it to read them, but I also need it to be secure and use intval.. help Hi guys, I've got a line of code that asks for a column called "distance_completed" to be displayed as part of a string. This column tells users how far people have run in a running race. I set up this field in my database to 11,3 so all distances appear with a decimal at the end, and then 3 digits after the decimal place. How would I alter the code so that the numbers that don't have any information in the places section just appear as integers Eg: 42 instead of 42.000 (for someone who ran exaclty 42km) and those that do have information in the decimal places appear correctly (eg: if a person ran 42km and 195m, it would appear as 42.195). I think this is probably the only line of code that would need modification: Code: [Select] echo ($row['time'] != null)?$row["time"]:"dnf at ".$row["distance_completed"]."km."; Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim I want to find the first sentence in a string without counting decimals. Here is the code I have, but I still want it to display the decimals, but I don't want it to count as the end of a sentence. $content = "This is my test string which is 3.5% of what I'm trying to do. This is only a test."; Code: [Select] function first_sentence($content) { if(preg_match('/[0-9]+\.[0-9]/', $content, $num)) { $number = "$num[0]"; $content = ereg_replace("$number","", $content); } preg_match('/^.*[^\s](\.|\?|\!)/U', $content, $match); $string = $match[0]; $title_count = strlen($match[0]); if($title_count > "6"){ return "$match[0]"; } else { $content2 = ereg_replace("$match[0]","", $content); preg_match('/^.*[^\s](\.|\?|\!)/U', $content2, $step); return "$match[0] $step[0]"; }} Currently this is what it displays: This is my test string which is % of what I'm trying to do. This is what I want it to display: This is my test string which is 3.5% of what I'm trying to do. Hi - To me, this doesn't make sense. My Order form uploads product weights in an array . If I echo out those weights they are fine ie 25.25 However, when I try to update the DB for some reason, the for loop strips out all but the first digit, so 25.25 becomes '2' or indeed if I had entered 9999999 it just '9' is entered in to the DB. I have tried using number_format to pre-process the decimals, - but I get an error saying you can not use it in a write format. Many Thanks to anyone who can help with this !! PS - I have abbreviated the below code for clarity: Code: [Select] $weight = $_POST['weight']; for ($i = 0; $i < $numloops ; $i++) { $sql =" UPDATE `confirmedorder` SET orderid = '$orderid[$i]', weight='$weight[$i]',status='finished', ordervalue='$ordervalue' WHERE customerid = $customerid "; $this->db->query($sql); } Hi there. I am trying to display numbers if they have the numbers like: number_format($price,2) This gives us two decimal places i.e 7.23 Now thats fine, I would like to round the last two decimal places. I would like to make it 7.25, (rounding it from 7.23 to 7.25) Similarly making: 12.44 to 12.45 33.18 to 33.20 52.13 to 52.15 So actually rounding the last two places. Coz obviously customers won't be able to pay 52 dollars 13 cents. So therefore rounding the last cent's (decimal part) making it to 52.15 Thank you. All comments and feedback are welcomed. (d Ok so say I have php do some calculations for me Code: [Select] $Value1 = 300; $Value2 = 100000; $FirstRatio = $Value1 / $Value2; $Value3 = 8000; $Value4 = 6000000; $SecondRatio = $Value3 / $Value4; $FirstRatio = 0.003 $SecondRatio = 0.0013 How would I go about doing these calculations and then sorting $FirstRatio and $SecondRatio and then it would take the highest ratio ($FirstRatio) and it would echo the value? I am currently working on a date range script and wondering if anybody think of an easier way to do this, doing up to next 8 weeks? This one starts on a Sunday. I also need to do one starting on a Monday (will figure that one later) $thisweek = date("Y-m-d"); $week = date('w', strtotime($thisweek)); $date = new DateTime($thisweek); $firstWeek = $date->modify("-".$week." day")->format("M d"); $endWeek = $date->modify("+6 day")->format("M d"); echo $firstWeek." - "; echo $endWeek; $nextweek = date(("Y-m-d"), strtotime("+7 Days")); $week1 = date('w', strtotime($nextweek)); $date1 = new DateTime($nextweek); $firstWeek1 = $date1->modify("-".$week1." day")->format("M d"); $endWeek1 = $date1->modify("+6 day")->format("M d"); echo $firstWeek1." - "; echo $endWeek1;
This works if say I do 192.168.0.1 - 192.168.1.254 it will work. However doing 192.168.0.1 - 192.168.1.10 will only generate up to .10 on both IP schemes. I see why, but I cannot figure out a way around this... Thanks! $start = explode('.', '192.168.10.1'); $end = explode('.', '192.168.11.10'); /** * Final output... */ $a = 0; $b = 0; $c = 0; $d = 0; // First segment for ($a = $start[0]; $a < 1 + $end[0]; $a++) { // Second segment for ($b = $start[1]; $b < 1 + $end[1]; $b++) { // Third segment for ($c = $start[2]; $c < 1 + $end[2]; $c++) { // Fourth segment for ($d = $start[3]; $d < 1 + $end[3]; $d++) { echo "{$a}.{$b}.{$c}.{$d}<br />"; } } } } Why is this not working? Code: [Select] $result = mysql_query("SELECT * FROM contacts WHERE type = 'consumer' AND sent BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("-7 days"))."'") or die(mysql_error()); $numrows = mysql_num_rows($result); if($numrows < 0 ){ echo "No records found"; } The record that is stored in the sent column is like this "2011-11-03 14:42:12", so there is a record in there, but nothing is showing up. Can anyone see why? thanks in advance I have range of categories from 1 to 999 With this is piece of code: foreach (range(96,204) as $number) if (Tools::getValue('id_category') == $number) return; $this->filterResults(); return $this->display( __FILE__, 'block-center-filter.tpl'); iw managed to avoid display of 'block-center-filter.tpl' in that range but it shows in every other categories. What i need is opposite... i would like to dont show except in that range... how to do that? Hello, I'm very disapointed because I don't know how do it this. I'm explain. I have a database with one input date_arrival and second date_departure. Two dates are saved in SQL format : 2014-03-02. After my SQL request to select all dates in database I'd like to add dates between date_arrival and date_departure and for each line. For example I have date_arrival date_departure line 1 : 2014-02-01 2014-02-05 line 2 : 2014-02-10 2014-02-15 In fact at the end, I have to send the result like this (with JSON) : ["2014-02-01","2014-02-02","2014-02-03","2014-02-04","2014-02-05","2014-02-10","2014-02-11","2014-02-12","2014-02-13","2014-02-14","2014-02-15"] Can you give me some help to add intermediates values in an array ? Thx if i want find included a word in the a range how can i do it? example : Quote array("problem is an obstacle, impediment, difficulty or challenge, or any situation that invites resolution; the resolution of which is recognized as a solutionquestion raised for inquiry, consideration, or solution proposition in mathematics or physics stating something to be done"); how can i find only start 20 charecter and my found word after 20 character by end example :if my word be inquiry i want find :...soluti Quote onquestion raised for inquiryconsideration, or solution proposition... [/size] Hi, I am trying to come up with the best way to create a range voting form. Each candidate will have a "confidence" value associated with the choice.(using a pulldown menu?) So for March Madness it would be: Team ....... Confidence Value..... each team could only be voted to finish the tournament in a particular place, and a value would be associated with that choice. The total choices possible determines the range of confidence value possible. So....if there are 16 teams to vote on....the confidence value would range from 1-16. The voter would assign his highest available value to the team he was most confident in landing in that particular position. Example: 16 teams - 16 conf vals - if certain Duke will end up at #1 - then vote : #1 = Duke, conf val 16 next, if almost as certain that NC will end up last - then vote: #16 = NC, conf val 15 next most certain "", conf val 14 and so on.... the tricky part is making sure that the form code validates each conf val so that it is used, but used on ly once.... ideally the form could return values that could then be imported into excel and comopared. has this been done somewhere? Can you help ? hope so.... thanks!! Okay we are using a javascript, but the javascript that the site comes from has bans all irans ips... and it loads slow for those people, how would I place a if statement saying dont load this javascript if in Iran, thanks... I know how to do it, but I can't find a real set number, and I would use just 1 ip but the guy has dynamic... thanks ahead of time |