简体   繁体   English

中间使用逗号分隔符在文本框中搜索多个键

[英]Searching multiple keys in text-box using coma seperator in between

I have a database and i like to search multiple primary keys separated by comas and display the respective rows in the next page . 我有一个数据库,我想搜索多个用逗号分隔的主键,并在下一页显示相应的行。 For example i have a table with 5 rows and the primary keys are like 1,2,3,4,5. 例如,我有一个有5行的表,主键像1,2,3,4,5。 Now in my search text-box if I type 1,2,3 it should display the first 3 columns in the next page. 现在,如果我输入1,2,3,则在搜索文本框中,它将在下一页显示前3列。 I am a beginner to php , so i don't now whether it is possible .I have done the search for a single key and it is working fine. 我是php的初学者,所以现在不知道是否有可能。我已经完成了对单个键的搜索,并且工作正常。

Your textbox contains a string with comma separated values? 您的文本框包含带逗号分隔值的字符串吗?

If so, you should be fine using the IN word like the previous answer, but comming from a PHP form: 如果是这样,您可以像前面的答案一样使用IN单词,但应该来自PHP形式:

LEAVING SECURITY AS AN OBVIOUS @TODO 作为显而易见的@TODO保持安全

$keys = $_POST['keys'];

$query = 'SELECT * FROM table WHERE id IN (' . $keys . ')';
$result = $whatever_object_you_using_for_database->query($query);

Would be great if you could uptade your question with the code you've tried, even the HTML code 如果您可以用自己尝试过的代码(甚至是HTML代码)更新问题,那将是很好的选择

用于:

SELECT * FROM your_table WHERE id IN (1,2,4,6,88);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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