MYSQL PHP - get float LIKE $float

前端 未结 3 1473
太阳男子
太阳男子 2021-01-28 02:47

I want to get rows with floats like my $float.

I used this code:

$float = $_GET[\'float\'];

$requst = mysql_fetch_array(mysql_query(\"SELEC         


        
相关标签:
3条回答
  • 2021-01-28 03:27

    How about select * from floats where floor(float) = $floor;?

    0 讨论(0)
  • 2021-01-28 03:28

    Your variable already has a decimal point in it.

    "SELECT * FROM floats WHERE float LIKE '$float%'"

    If your float is 34.567 your statement executes as find like '34.567.%' which isn't finding any results.

    Edit: how about this then?

    "SELECT * FROM floats WHERE abs(float-$float)<1;"

    That will bring in anything within 1?

    Having said that, although you can keep floats in mysql, it might be safer to keep them as decimals with a limited number of points after the decimal.

    0 讨论(0)
  • 2021-01-28 03:38

    Try This

    $requst = mysql_query("SELECT * FROM floats WHERE float LIKE'$float.%%%%%%%'");
    while ($r = mysql_fetch_array($request)) {
    
        echo $r['float'];
    
    }
    
    0 讨论(0)
提交回复
热议问题