Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Need to bookmark the page or current video running on the page using GET method.

Hi, Thanks in advance. I need to bookmark the page or current video running on the page, so that user can play the video on clicking on the bookmarked video in my project using GET Method. Can anyone please suggest me some approach to do this.

6 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

Is only one video ever being bookmarked? You could set something up to fire on page load. Add a column to your user or user-profile table called something like 'last-watched'. On page load, grab the ID of the video on the page and store it in that last-watched column.

If you are going to store the bookmarks for more than the current session you need to have a database store the bookmarks. Then you can recall the bookmarks in a later session.

Hi Ted, Thanks for the reply. I want on click the current video playing gets bookmarked. And whenever user opens it's bookmark tab he/she can see all the bookmarked videos. What I am trying is: On click on button or any link, I get the url variables as url contains the topic id which is unique, and from there I can select the topic name and can make it as a href link. So, that whenever user opens the bookmark tab he/she can view all bookmarked videos and can watch the videos directly from there. And alss we can store it it DB for each user, so that every bookmarked videos can be seen by the user. But I am unable to implement this.

Can you write a code that communicates with the database? Is it an issue setting up the database? Is it the PHP to process the clicks to build the commands? Or is it a combination of all three?

Hi Ted, Below is the code for toc.php - In this file I am picking up all the topics from the database and on each and every topic a video runs with it's unique id.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
<!-- style for radio button jquery start -->
<style type="text/css">
    .box{
        padding: 20px;
        display: none;
        margin-top: 20px;
        border: 1px solid #000;

    }

</style>

<!-- style for radio button jquery end -->
<!-- script for radio button jquery start -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('input[type="radio"]').click(function(){
        if($(this).attr("value")=="notes"){
            $(".box").not(".notes").hide();
            $(".notes").show();
        }
        if($(this).attr("value")=="search"){
            $(".box").not(".search").hide();
            $(".search").show();
        }
        if($(this).attr("value")=="transcript"){
            $(".box").not(".transcript").hide();
            $(".transcript").show();
        }
        if($(this).attr("value")=="bookmark"){
            $(".box").not(".bookmark").hide();
            $(".bookmark").show();
        }
    });
});
</script>
<!-- script for radio button jquery ends -->


</head>
<div style="float:left;">  
<?php
     include('inc/db.php');
     $module_id = $_GET["moduleid"];


    // select from topic_detils table
    $select = $conn->query("SELECT * FROM topic_details");
    foreach($select as $path){

    $video_save_name = $path["video_save_name"];
    $topic_name = $path["topic_name"];
    $topic_id = $path["id"];
?>
<a href="toc.php?videoid=<?php echo $video_save_name; ?>&topicid=<?php echo $topic_id; ?>&moduleid=<?php echo $module_id;?>" id="<?php echo $topic_id; ?>"> <?php echo "$topic_name <br>";?> </a>
<?php } 

 // select notes
   $select = $conn->query("SELECT * FROM module_details WHERE id = $module_id");
   foreach($select as $module){
   $notes = $module["notes"];
   }
   ?>
</div>
<?php
    if(isset($_GET['videoid'])) {

        $topicid=$_GET['topicid'];

        $select = $conn->query("SELECT * FROM topic_details WHERE id='$topicid'");
        foreach($select as $path){

        $video_save_name = $path["video_save_name"];
        $topic_name = $path["topic_name"];
        $topic_id = $path["id"];
        }

?>      

<div style="float:left;">
    <video width="768" height="480" controls>
      <source src="../kw/course-manage/course/uploads/videos/<?php echo $video_save_name; ?>" type="video/mp4">
      Your browser does not support HTML5 video.
    </video>
</div>

<?php } 

   // Notes
   if(isset($_POST["save_notes"])){

    $notes = $_POST["user_notes"];
    // insert into the database 
    $notes1 = $conn->query("UPDATE module_details SET notes = '$notes' WHERE id = $module_id");
}


?>
<!-- radio button div -->
<div style="float:right">
        <label><input type="radio" name="buttonRadio" value="notes"> Notes </label>
        <label><input type="radio" name="buttonRadio" value="search"> Search </label>
        <label><input type="radio" name="buttonRadio" value="transcript"> Transcript </label>
        <label><input type="radio" name="buttonRadio" value="bookmark"> Bookmark </label>
    </div>

    <div class="notes box" style="display:none">
    <form method="post" action="">
    <textarea name="user_notes"><?php echo $notes; ?></textarea><br>
    <input type="submit" name="save_notes" value="Save">
    </form>
    </div>
    <div class="search box" style="display:none">
    <form method="post" action="">
    <input type="text" name="user_search">
    <input type="submit" name="search" value="Go">
    </form>
    </div>
    <?php
    // Search 
   if(isset($_POST["search"])){

       $user_search = $_POST["user_search"];

       // select key words from the table

       $select = $conn->query("SELECT * FROM topic_details WHERE(keywords LIKE '%$user_search%')");
       foreach($select as $keywords){
           $topic_name = $keywords["topic_name"];
           $topic_id = $keywords["id"];
           $video_save_name = $keywords["video_save_name"]; ?>
          <a href="toc.php?videoid=<?php echo $video_save_name; ?>&topicid=<?php echo $topic_id; ?>&moduleid=<?php echo $module_id;?>"> <?php echo "$topic_name <br>"; ?> </a>
    <?php   
       }
   }
   ?>
    <div class="transcript box" style="display:none">
    <?php
    if(isset($_GET["videoid"])){

        $topic_id = $_GET["topicid"];
        // select transcript from topic_details 
        $select = $conn->query("SELECT * FROM topic_details WHERE id = '$topic_id'");
        foreach($select as $transcripts){
            $topic_transcript = $transcripts["transcript"];
            echo "$topic_transcript";

        }

    }
    ?>
    </div>

    <div class="bookmark box" id="demo" style="display:none; float:right">
    </div>



</html>

On Click of any topic, the url changes to: http://localhost/kw_user/toc.php?videoid=video3.mp4&topicid=3&moduleid=1

So, I want when I click the bookmark radio button, a new button gets added, and on the click of that new button the video gets saved with its name under the bookmark tab. And I Can play the vidoe any time.

Thanks.

formatted code for you. Please look at how I did it for future reference and refer to the Markdown Cheatsheet for future reference.

I have a difficult time reading your code. You need to separate the CSS and JavaScript into their own files.

??? Unable to see the code.

I can see your code. It is just difficult to understand with the CSS and JavaScript mixed in as well.