Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP查询中编写LIKE语句?_Php_Android_Android Studio_Jsonexception - Fatal编程技术网

如何在PHP查询中编写LIKE语句?

如何在PHP查询中编写LIKE语句?,php,android,android-studio,jsonexception,Php,Android,Android Studio,Jsonexception,我正在创建一个应用程序,可以通过使用输入单词的最后一个字母来检索单词。例如,在我现有的数据库中,顺序是Apple>Elephant>Train>Nerve>Education>Paper>,我将输入Recipe,因为这是前一个单词的最后一个字母。我的问题是我无法得到回应。应用程序必须给出一个以前一个单词的最后一个字母开头的单词。所以在tblcheckword中,响应必须是Emphasis或Empire,因为在我的查询中,它是以rand表示的,并且限制为1 SELECT word FROM tbl

我正在创建一个应用程序,可以通过使用输入单词的最后一个字母来检索单词。例如,在我现有的数据库中,顺序是Apple>Elephant>Train>Nerve>Education>Paper>,我将输入Recipe,因为这是前一个单词的最后一个字母。我的问题是我无法得到回应。应用程序必须给出一个以前一个单词的最后一个字母开头的单词。所以在tblcheckword中,响应必须是Emphasis或Empire,因为在我的查询中,它是以rand表示的,并且限制为1

SELECT word FROM tblcheckword WHERE word LIKE '$word.%' ORDER BY rand() NOT IN (SELECT ig_word FROM tbltempgame) LIMIT 1;
我使用LIKE语句获取输入单词的最后一个字母。但我还是犯了一个错误

这是我的PHP文件checkplsv2.PHP

<?php
$con = mysqli_connect("localhost", "root", "1234", "check") or die ("Error ".mysqli_error($con));
$word = $_POST["word"];
$sql = "SELECT word FROM tblcheckword where word like '$word.%' order by rand() not in (select ig_word from tbltempgame) LIMIT 1";
$result = mysqli_query($con, $sql) or die("Error in selecting ".mysqli_error($con));

$response = array();
if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_array($result))
    {
        array_push($response, array("id"=>$row[0],"ig_word"=>$row[1],"meaning"=>$row[2]));
        $retrieve = $row[1];
    }
    echo json_encode(array("server_response" => $retrieve));
}else{
    echo "Retrieve failed";
}

mysqli_close($con);


?>
您的sql不正确

试试这个:

 $sql = "SELECT `word` FROM `tblcheckword`WHERE `word` LIKE ".$word."% NOT IN(select ig_word from tbltempgame)  ORDER BY RAND()  LIMIT 1";
您的sql不正确

试试这个:

 $sql = "SELECT `word` FROM `tblcheckword`WHERE `word` LIKE ".$word."% NOT IN(select ig_word from tbltempgame)  ORDER BY RAND()  LIMIT 1";

您的sql查询显然不正确。PHP查询实际上是一个旧的html解析器库,它与sql无关。think jQueryYou sql查询显然不正确。PHP查询实际上是一个旧的html解析器库,它与sql无关。think jQueryThis也不正确。订单必须放在WHERE条件之后…我仍然有一个错误。上面是这么说的。E/log_标记:失败的数据是:选择错误您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,了解在第1行编辑答案的“%order by rand not in select ig_word from tbltempgame LIMIT 1”附近使用的正确语法。E/log_标记:失败的数据是:选择错误您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解可在第1行的“WHERE'word'LIKE Recipe%NOT INselect ig_word from tbltempgame LIMIT 1”附近使用的正确语法,Sir@KinshukLahiriSorry,我还没有更新@pedrounan提到的顺序。请现在检查,先生。这也是不正确的。订单必须放在WHERE条件之后…我仍然有一个错误。上面是这么说的。E/log_标记:失败的数据是:选择错误您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,了解在第1行编辑答案的“%order by rand not in select ig_word from tbltempgame LIMIT 1”附近使用的正确语法。E/log_标记:失败的数据是:选择错误您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解可在第1行的“WHERE'word'LIKE Recipe%NOT INselect ig_word from tbltempgame LIMIT 1”附近使用的正确语法,Sir@KinshukLahiriSorry,我还没有更新@pedrounan提到的顺序。先生,请现在查一下。
09-04 19:23:52.051 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.051 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.051 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.051 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.061 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.071 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.071 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.071 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.081 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.091 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:23:52.091 11820-11820/com.example.keam.lastnato E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.keam.lastnato.MainActivity.access$super
09-04 19:24:01.960 11820-12003/com.example.keam.lastnato E/pass 1: connection success 
09-04 19:24:01.960 11820-12003/com.example.keam.lastnato E/pass 2: connection success 
09-04 19:24:01.960 11820-11820/com.example.keam.lastnato E/Fail 3: org.json.JSONException: Value Retrieve of type java.lang.String cannot be converted to JSONObject
09-04 19:24:01.960 11820-11820/com.example.keam.lastnato E/log_tag: Failed data was: Retrieve failed
 $sql = "SELECT `word` FROM `tblcheckword`WHERE `word` LIKE ".$word."% NOT IN(select ig_word from tbltempgame)  ORDER BY RAND()  LIMIT 1";