php - Retrieve a similar query -
in nutshell, page populates course, , @ bottom have 3 boxes similar courses, , similar course cannot current course refered id. similar in terms of course_title.
below how current course populated:
$get_crs_similar = "select * courses course_id='$course_id'";
i retrieve 3 similar course, thinking retrieve last similar course first 1, , second last similar course, , third similar course, 3 cannot equal current course.
any appreciated.
html similar courses
<div class="well-none"> <div id="mycarousel" class="carousel slide"> <div class="carousel-inner"> <div class="item active"> <div class="row"> <h4> <?php echo $crs_title2; ?></h4> <div class="col-sm-3 col-xs-6"><a href="coursepage.php?crs_id=4656" class="thumbnail"><img src="content/negotiation.png" alt="image" width="250" height="250" class="img-responsive"></a> </div> <div class="col-sm-3 col-xs-6"><a href="#x" class="thumbnail"><img src="content/azure2.png" alt="image" class="img-responsive"></a> </div> <div class="col-sm-3 col-xs-6"><a href="#x" class="thumbnail"><img src="content/server.png" alt="image" class="img-responsive"></a> </div> <div class="col-sm-3 col-xs-6"><a href="#x" class="thumbnail"><img src="content/azure3.png" alt="image" class="img-responsive"></a> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>
use self-join:
select c1.* courses c1 join courses c2 on c1.course_title = c2.course_title , c1.course_id != c2.course_id c2.course_id = $course_id limit 3
this return 3 courses have same title given course, not same course.