close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 | 918 views | 4 replies |

dave315749

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

anonymous

Dave,

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.

php:
<?php 
foreach ($courses AS $item) { ?>

<?php
mysql_select_db
($database_YourDB$YourDB);
$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 />

<?php
mysql_free_result
($course);
?>
<?php 
?>
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 ";
$favorites_list_array=explode(",",$row_Recordset1['related_course_ids']);
foreach($id_list_array as $id){
if($id!='' && is_numeric($id)){
$id_query.="course_id=$id OR ";
$list=true;
}
}
if($list){
$id_query=substr($id_query,0,-3);
}else{
$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?

Tom

Sign in to reply to this post

dave315749

Yes

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

tutorial_mysql_in_and_between.php3

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

Content

rating

Layout

rating

Ease of use

rating

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...