sql - MYSQL/PHP: How do you Order By Starting point in a string? -
select sql_calc_found_rows posts.*, case when postmeta.meta_value regexp '$regex' 1 else 0 end keyword_in_title, match ( posts.post_content ) against ( '".addslashes( $s )."' ) mysql_score $wpdb->posts posts, $wpdb->postmeta postmeta posts.post_date_gmt <= now() , postmeta.post_id = posts.id , postmeta.meta_key='_headspace_page_title' , posts.post_password = '' , posts.post_status = 'publish' , posts.post_type != 'attachment' , ( postmeta.meta_value regexp '$regex' or posts.post_content regexp '$regex') group posts.id order charindex($s, 'keyword_in_title') desc limit $offset, $limit
as order issue (apart escaping issue @gumbo pointed out in comment), charindex
not valid mysql string function. locate
function looks identical (at least cursory glance between docs on sqlserver , mysql)...
$s = mysql_real_escape_string($s); $order = 'order locate(\''.$s.'\', `keyword_in_title`) desc';
Comments
Post a Comment