Php SQL以错误的顺序从foreach循环中检索数据 [英] Php SQL retrieving data from foreach loop in wrong order

查看:96
本文介绍了Php SQL以错误的顺序从foreach循环中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已根据输入到搜索输入中的多个单词编写代码来检索数据库数据。它正在工作,但检索到的数据不会按照输入搜索输入/ foreach循环的顺序返回。有什么建议吗?



谢谢



我的尝试:



I have written code to retrieve database data according to multiple words entered into a search input. It's working but the data retrieved is not coming back in the same order it was entered into the search input/foreach loop. any suggestions?

thanks

What I have tried:

$word=$_POST['word']; 
$word3 = $_POST['word']; 
$word = explode(";", $word);
$noOfWords = count($word);
$word2 = $word3;

if($noOfWords == 1){
    $searchString = " word_eng LIKE '".$word3."%'";
    
}
else { 

$searchString = $whereClause = "";
foreach($word as $word){
  $searchString .= " OR word_eng LIKE '".$word."'";
  
  echo $word;
}

}

$whereClause = ($searchString != "") ? " WHERE ".preg_replace('/OR/', '', $searchString, 1) : $whereClause;

$sql = "SELECT word_eng FROM words ".$whereClause ." LIMIT 17 ";

推荐答案

word =


_POST ['word'];
_POST['word'];


word3 =


这篇关于Php SQL以错误的顺序从foreach循环中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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