简体   繁体   中英

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. Now in my search text-box if I type 1,2,3 it should display the first 3 columns in the next page. 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.

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:

LEAVING SECURITY AS AN OBVIOUS @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

用于:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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