Page 1 of 1

[SOLVED] Putting multiple values from list into one field

Posted: Tue Feb 03, 2004 5:58 pm
by rush989
Hi there,

I'm kinda stumped on how to do this. I have a list box where I can select multiple things by holding down control (example at: http://www.mypartz.com/example.html). I was wondering how I could get the selected items into a variable so I can put them into one field in my database. The values can be in the variable separated by spaces or commas. This is so I can use my friend's search script on the variable to display certain rows.

When I try it out by using
$query = "INSERT INTO reviews (keywords) VALUES ('$keywords')";
it only puts in the last value selected.

I'm a beginner in php so I don't really know much but as long as it's in a variable I will know what to do.

One other thing is that the search script only searches one field in the database. How can I get it to search multiple fields? Right now it searches the website_link field but I would also like it to search the keywords and website_title field.

Here is the code the search script uses:
$query = "select * FROM reviews WHERE website_link LIKE \"%$trimmed%\"
order by website_link";


Thanks everyone!

Posted: Tue Feb 03, 2004 6:02 pm
by markl999
<select name="keywords" .. change it to
<select name="keywords[]"

$query = "INSERT INTO reviews (keywords) VALUES ('$keywords')";
change it to
$query = "INSERT INTO reviews (keywords) VALUES ('".join(',', $keywords)."')";

$query = "select * FROM reviews WHERE website_link LIKE \"%$trimmed%\" order by website_link";
change to
$query = "select * FROM reviews WHERE
website_link LIKE '%$trimmed%' OR
keywords LIKE '%$trimmed%' OR
website_title LIKE '%$trimmed%'
ORDER BY
website_link";

Posted: Tue Feb 03, 2004 6:20 pm
by rush989
Awesome!

They both work. Thanks man!