简体   繁体   中英

Check sql match query

I have a wordpress post title $title = 'my post title';

I have a table called interlinks where I store all my post titles, urls, and siteurls or my entire network.

This query matches my title with all the titles in the interlinks table.

Please check if my query is correct. Thank you. I have a feeling it's a big buggy.

$query_related_posts_network = mysql_query(
   "SELECT "
   "   posttitle, "
   "   posturl, "
   "   siteurl, "
   "   MATCH (posttitle,posturl,siteurl) AGAINST ('$title') AS score "
   "FROM "
   "   interlinks "
   "WHERE "
   "   MATCH (posttitle,posturl,siteurl) AGAINST ('$title') AND "
   "   `siteurl` <> '$blogurl' "
   "LIMIT 15");

The only thing I can see is:

Don't forget to escape the string variables you put in your SQL queries, using mysql_real_escape_string() .

$query_related_posts_network = mysql_query("SELECT posttitle, posturl, siteurl,
  MATCH (posttitle,posturl,siteurl) AGAINST ('".mysql_real_escape_string($title)."') AS score
  FROM interlinks
  WHERE MATCH (posttitle,posturl,siteurl) AGAINST ('".mysql_real_escape_string($title)."')
    AND `siteurl` <> '".mysql_real_escape_string($blogurl)."' LIMIT 15");

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM