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);
}
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.