Pattern matching a mysql result with an array

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
sleazyfrank
Forum Commoner
Posts: 40
Joined: Fri Aug 19, 2005 3:59 am
Location: Horsham, West Sussex

Pattern matching a mysql result with an array

Post by sleazyfrank »

Hi there - I have an array of topics and a sql query that pulls out a series of subject topics related to a course in my database.

I want to create a select box that contains that array of topics and then sets to Selected each of those that match the resultset. The aim is that this will allow an editor to show which topics a course is assigned too and I can then select more or deselect current ones.

any ideas would be great

cheers

frank
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Put the results of your query in an array. Then, when you're looping through your array of topics, call in_array() and if it returns true, set that topic to selected.

Remember that you have to set the `multiple` property in order to have multiple options selectable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply