dongshi1148 2013-05-04 07:35
浏览 18

如何从PHP中的范围获得接近值

How to find nearest value from mysql database table of give value, what i want to do is:

CASE1: if i am giving input 2500 to pincode then i am retrieving record corresponding to that pincode value from database.

CASE2: if record not exits for entered pincode(2500) , i have to get nearest value of 2500 and its corresponding records too.

Stored procedure i am currently calling for CASE1 sp_findlocation('XXXXXXXX','2500',@addresss)

DELIMITER $$
USE `test`$$
DROP PROCEDURE IF EXISTS `sp_findlocation`$$
CREATE PROCEDURE `sp_findlocation`(IN mobile VARCHAR(20),IN pincode VARCHAR(20),OUT address VARCHAR(100))
BEGIN   
    IF(pincode IS NOT NULL AND pincode!= '') THEN
        SET @c1 = '';
        SET @c2 = '';
        SET @c3 = '';
        SET @qry='select locality,store_name,contact_number INTO @c1,@c2,@c3 from test_upload where pin=? limit 1';
        PREPARE stmt FROM @qry;
        SET @c = pincode;
        EXECUTE stmt USING @c;
        DEALLOCATE PREPARE stmt;
        IF(@c1!='' || @c2!=''||@c3!='') THEN    
            SET address= CONCAT(@c1, '|',@c2,'|',@c3);      
        ELSE
            SET address= "No Result";
        END IF; 
    ELSE    
        SET address="Please enter valid pin code";
    END IF; 
END$$
DELIMITER ;

what i will do for geting records including CASE2?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计