[SOLVED] Putting multiple values from list into one field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rush989
Forum Newbie
Posts: 4
Joined: Tue Feb 03, 2004 5:58 pm

[SOLVED] Putting multiple values from list into one field

Post 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!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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";
rush989
Forum Newbie
Posts: 4
Joined: Tue Feb 03, 2004 5:58 pm

Post by rush989 »

Awesome!

They both work. Thanks man!
Post Reply