dongpan2788 2013-12-18 04:55
浏览 38

PHP返回不在Kohana工作

I tried running the following code and it supposed to pick the value from the database but not picking.

            $val = doautocomp('Brisbane');

        HTTP::redirect($url_address.'/hotel-search/go/' . $val);
        exit;
    }
    else {
        HTTP::redirect($url_address.'/hotel-search/error');
        exit;
    }
}
function seoUrl($string) {
        $string = strtolower($string);
        $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
        $string = preg_replace("/[\s-]+/", " ", $string);
        $string = preg_replace("/[\s_]/", "-", $string);
        return $string;
}
function doautocomp($mval) {
    $linker = mysql_connect('localhost', 'root', 'pass');
    $result3 = mysql_query("SELECT name FROM the.autocompletes where name LIKE '".$mval."%' LIMIT 0,1");
    while($row = mysql_fetch_array($result3))
      {
          $val1 = $row['name'];
          $mval = seoUrl($val1);

      }
      return $mval;
      mysql_close($linker);
}  

I also tried as but still its not working. RETURN TEST

        $val = doautocomp('Brisbane');

        HTTP::redirect($url_address.'/hotel-search/go/' . $val);
        exit;
    }
    else {
        HTTP::redirect($url_address.'/hotel-search/error');
        exit;
    }
}
function seoUrl($string) {
        $string = strtolower($string);
        $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
        $string = preg_replace("/[\s-]+/", " ", $string);
        $string = preg_replace("/[\s_]/", "-", $string);
        return $string;
}
function doautocomp($mval) {
    $linker = mysql_connect('localhost', 'root', 'pass');
    $result3 = mysql_query("SELECT name FROM the.autocompletes where name LIKE '".$mval."%' LIMIT 0,1");
    while($row = mysql_fetch_array($result3))
      {
          $val1 = $row['name'];
          $mval = seoUrl($val1);

      }
      return "test"; //$mval;
      mysql_close($linker);
}  
  • 写回答

1条回答 默认 最新

  • dongre9937 2013-12-20 10:03
    关注

    I have some problems understanding your code right. You are using a framework with a good database class. Why do you use "mysql_connect". Your "mysql_close()" comes under the "return" statement. So maybe your last connection isn't closed right. Did you try a return "TEST" before mysql is used?

    You should write your code more like this:

    function doautocomp($mval) {
    
        $row = Database::instance()->query(Database::SELECT,
            DB::select('name')
                ->from('autocompletes')
                ->where('name','LIKE',$mval.'%')
                ->limit(1)
            )->current();
    
        if ($row === FALSE)
        {
            return "";
        }
    
        $val1 = $row['name'];
        $mval = seoUrl($val1);
    
        return $mval;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题