close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


find individual comma separated values in database

Thread began 1/24/2010 1:02 am by dave315749 | Last modified 4/25/2010 1:45 am by CraigR | 985 views | 4 replies |


find individual comma separated values in database

Administrator side has a multi select field for related courses. It gets saved as 1,5,10,14

On my courses page i want to show find the related courses using their id's of 1,5,10,14.

Do they have to be exploded first?

what kind of query would i have to write to find the individual records? Is there a webassist extension that i could use for this or is it pretty simple?

Sign in to reply to this post



Without understanding you multi-select code, I cannot be positive that what I suggest will work.

But, if your multi-select is actually creating an array - meaning it is saving the entire sting of ID is one variable, than you can just loop through each item. You could do the same if it is a list.

Let's say your variable containing the array is $courses,

You could then create a for each loop which will query for the related info and then display it.

foreach ($courses AS $item) { ?>

$query_course "SELECT coursename, relatedinfo FROM courses WHERE id = '$item'";
$course mysql_query($query_course$YourDB) or die(mysql_error());
$row_course mysql_fetch_assoc($course);
$totalRows_course mysql_num_rows($course);

<p>Course: <?php echo $row_course['coursename']; ?></p>
<p>Related Info: <?php echo $row_course['relatedinfo']; ?></p>
<hr />

Sign in to reply to this post

tom250037Beta Tester

You could explode your comma separated string into an array, and then build a query that would pull the records for all those IDs, and then loop through that recordset on your page.

Right after your original recordset, you could have something like this.
This is assuming that your comma separated string is $row_Recordset1['related_course_ids']

$related_courses_query="WHERE 1=2";
if (isset($row_Recordset1['related_course_ids']) && $row_Recordset1['related_course_ids'] !=''){
$favorites_query="WHERE ";
foreach($id_list_array as $id){
if($id!='' && is_numeric($id)){
$id_query.="course_id=$id OR ";
$id_query="WHERE 1=2";

//then for your courses query
mysql_select_db($database_dbc, $dbc);
$query_rsCourses = "SELECT * FROM courses $id_query";
$getPhotos = mysql_query($query_rsCourses, $dbc) or die(mysql_error());
$row_rsCourses = mysql_fetch_assoc($rsCourses);

Then you can loop though the rsCourses recordset, and provide a link to each related course.

Is that what you were looking for?


Sign in to reply to this post



Yes but it looks semi complicated.. anyone know of any extensions that can do this on the fly?

Sign in to reply to this post

CraigRBeta Tester

if all you are looking to do is find a row in your recordset which includes one of the numbers, you could use the MySQL operator IN

"SELECT * FROM courses WHERE id IN ('1', '5', '10', '14')"

if the parameters are integers rather than strings you may not need the inverted commas


Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...