String split和join从数据库中获取字符串

时间:2014-04-19 22:01:10

标签: javascript database string join split

我有一个带有拆分和连接功能的java脚本,但是我的数据给了我一个“超出限制”的错误代码所以我决定使用数据库存储字符串并从中获取字符串..我的现有的java脚本代码在这里。

 function myFunction()
 {
    var str = document.getElementById("entryInput");
    var entryId = str.value;
    var str = (entryId); 
    var res = str.split('how are you brother').join('how r u bro')
    .split('are you ok').join('r u ok')
    .split('what is going on').join('wag one');
    document.getElementById('translation').innerHTML=res;
 };

我搜索并找到了这个数据库连接相关的行,但经过多次尝试后我无法正常工作所以请帮助我......

@mysql_connect(DB_HOST, DB_USER, DB_PWD) or die(mysql_error());
@mysql_select_db(DB_NAME) or die(mysql_error());

$str = "SELECT * FROM words WHERE word_title= "%$_GET[word]%";
$str = mysql_query($query);

编辑并添加....

这是脚本附带的PHP代码,它逐字逐句地从数据库中获取字符串,但我希望javascript为我做。得到单词split并再次加入将创建一个连续的字符串...我需要得到的是从这个数据库中获取字符串并在jscript中使用它,如果可能的话...如果用户输入一个单词我需要它来获取它数据库...这是用户将使用的页面的链接.. Page that the user will type string like of different words stored in the database 它目前仅在javascript文件中翻译“你还好”到“你好吗”。所以我需要它从数据库中获取它感谢

function Search() {
    global $rewrite;

    $_GET['word'] = trim(str_replace(Array('%', '_'), Array('', ''), $_GET['word']));

    if ($_GET['type']) {
        $word = 'noword';
        $type = $_GET['type'];
    } elseif ($_GET['by']) {
        $word = $_GET['by'];
        $type = '';
    } elseif ($_GET['word']) {
        $word = $_GET['word'];
        if ($_GET['type'] == 'full') $type = 'full';
        else $type = '';
    } else {
        $word = '';
        $type = '';
    }

    if ($word != '') {
        $GLOBALS['page_title'] = $_GET['word'] .  ' - ' . $GLOBALS['page_title'];
        if ($type == 'full') {
            $select = "* ";
            $where = "word_title LIKE '%$_GET[word]%' OR word_desc LIKE '%$_GET[word]%' ";
            $order = "word_id DESC ";
        } elseif($type == 'latest') {
            $select = '* ';
            $where = "word_title LIKE '%$_GET[word]%' ";
            $order = "word_id DESC ";
        } else {
            $select = '* ';
            $where = "word_title LIKE '" . sqlesc($word) . "%' ";
            $order = "word_title ASC ";
        }
        $q = "SELECT $select FROM `words` WHERE $where ORDER BY $order ";
    } else {
        Redirect('index.php');
    }

由于

1 个答案:

答案 0 :(得分:0)

你应该试试这个:

$str = "SELECT * FROM words WHERE word_title LIKE "%$_GET[word]%";

或者

$str = "SELECT * FROM words WHERE word_title REGEXP "$_GET[word]";