字符串拆分和连接从数据库获取字符串 [英] String split and join get strings from database

查看:235
本文介绍了字符串拆分和连接从数据库获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作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 ru bro')
.split('are you ok')。 $ b .split('what is going on')。join('wag one');
document.getElementById('translation')。innerHTML = res;
};

我搜索并找到了这个数据库连接相关行,但是在我尝试了很多次之后,

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

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



编辑并添加....



这是PHP代码与脚本和它获取字符串从数据库一个字一个字,但我想像javascript为我做的。得到的词分裂和连接,这将使一个连续的字符串...我需要得到是从这个数据库获取字符串,并使用它在jscript如果可能...如果用户键入一个单词,我需要它从数据库中获取...这里是链接到用户将使用的页面。页面,用户将输入字符串类似于存储在数据库中的不同字词
它目前只翻译为你确定到ru ok因此我需要它从数据库中感谢

  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');
}

感谢

解决方案

您应该尝试这样:

  $ str =SELECT * FROM words WHERE word_title LIKE %$ _ GET [word]%; 

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


I have a working java script with split and join function, but the data I have is giving me an error code of "exceeding the limit" so i decided to use a database to store strings and get strings from there.. my existing java script code is here.

 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;
 };

I searched and found this database connection related lines but after I tried many times I couldn't make it work so please help me...

@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);

edited and added....

This is the PHP code that came with the script and it gets strings from database word by word but I want as javascript did for me. get the word split and join again which will make a continues strings... all i need to get is getting strings from this database and use it in jscript if possible... if the user types a word i need it to get it from the database... here is the link to the page that the user will use..Page that the user will type string like of different words stored in the database it currently translates only "are you ok" to "r u ok" which is in the javascript file. so i need it to get it from database thanks

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');
    }

Thanks

解决方案

You should try this:

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

Or

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

这篇关于字符串拆分和连接从数据库获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆