Jump to content


Photo

number problem


  • Please log in to reply
4 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 20 September 2006 - 03:01 PM

ok

a number is being sent with $_GET in the form: 150,000 i want to compare this with a variable containing a number. But when i use $tmp_price = explode(",",$_GET['pricemax']) the result is not how i would expect, ie $tmp_price[0] = 150 $tmp_price[1] = 000 ... was then going to put them together are 150000

Any ideas?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 20 September 2006 - 03:14 PM

?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 September 2006 - 03:20 PM

Rather than exploding the comma and then stiching the number back together. Use str_replace:
$tmp_price = $_GET['pricemax'];

// remove any commas from price max.
$price = str_replace(',', '', $tmp_price);


#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 03:25 PM

What's the format that you have in the variable, is it 150,000 or just 150000?

If it's just a case of removing the delimiter, then use str_replace()

$maxprice = str_replace(",", "", $_GET['maxprice']);

Regards
Huggie

EDIT: Too slow :(!
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 03:29 PM

ok

a number is being sent with $_GET in the form: 150,000 i want to compare this with a variable containing a number. But when i use $tmp_price = explode(",",$_GET['pricemax']) the result is not how i would expect, ie $tmp_price[0] = 150 $tmp_price[1] = 000 ... was then going to put them together are 150000

Any ideas?


If you do want to split it up you could do this:
<?php
$number = explode(',',$_GET['pricemax']);
$number = join('',$number);
?>

The other option you have been showed is better though.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users