kostenloser Webspace werbefrei: lima-city


YouTube-Video-Manager mit PHP, MySQL und jQuery

lima-cityForumProgrammiersprachenPHP, MySQL & .htaccess

  1. Autor dieses Themas

    mamam

    mamam hat kostenlosen Webspace.

    Hallo,
    Könnt ihr sagen wie ich die Datenbank machen muss
    Die Datenverbindung machen muss.?:wave:


    http://jdmweb.com/youtube-video-manager-with-php-mysql-jquery

    <?php
    
    define("table_name","myvideos");
    
    class MyVideo {
    
      //=======================================//
      //==========> Class Variables <==========//
      //=======================================//
      private $id;		//Id of the Video
      private $url;		//YouTube Url
      private $title;	//Video Title
    
    
    //=======================================================================================//
    //================================= Core Methods ========================================//
    //=======================================================================================//
      
    
      //=======================================//
      //============> Constructor <============//
      //=======================================//
      public function __construct($id=0,$url="",$title="")
      {
        $this->id=$id;
        $this->url = $url;
        $this->title = $title;
      }
      
      
      //=======================================//
      //======> Load a Video Via its ID <======//
      //=======================================//
      public function load($id){
        //Select the Video Information from DB
        $sql="SELECT * FROM ".table_name." WHERE video_id = $id LIMIT 1";
        $result=array(); $video = new MyVideo();
        $req = mysql_query($sql) or die("Erreur SQL !<br>".$sql."<br>".mysql_error());
        
        //Assign those Infomation to a MyVideo Object
        while($data= mysql_fetch_assoc($req)) {
          $MyVideo->id = $data[video_id];
          $MyVideo->url = $data[video_url];
          $MyVideo->title = $data[video_title];
        }
        
        return $MyVideo;    
      }
    
    
      //=======================================//
      //======> Get Video List From DB <=======//  
      //=======================================//
      public function getrecords()
      {
        //Select all videos from DB
        $sql="SELECT * FROM ".table_name."";
        $result=array();
        $req = mysql_query($sql) or die("SQL Error!<br>".$sql."<br>".mysql_error());
        while($data= mysql_fetch_assoc($req)) {
          $result[]=$data;
        }
        return $result;
      }  
      
      
      //==========================================//
      //== Display the form to add/edit a video ==//
      //==========================================//
      public function getVideoForm($videoid=0,$action="", $method="post"){
        //Load A Video if $videoid (Used to edit an existing video)
        if( (!empty($videoid)) && (is_numeric($videoid)) ){ 
          $video = MyVideo::load($videoid); 
        } else { 
          $video = new MyVideo(); 
        }
        
        //The Form Markup (Video Url, + Video Title)
        $form='<form action="'.$action.'" method="'.$method.'">
          <div class="regrow">
            <label class="inside" for="video_url">YouTube url:</label>
            <input type="text" name="video_url" class="text" value="'.$video->url.'" />
          </div>
          <div class="regrow">
            <label class="inside" for="video_title">Video Title:</label>
            <input type="text" name="video_title" class="text" value="'.$video->title.'" />
          </div>
          <div class="regrow">
            <input type="hidden" name="video_id" value="'.$video->id.'" />
            <input type="hidden" name="todo" value="savevideo" />
            <input type="submit" class="button" value="Send" /> 
            <input id="cancelctcform" type="button" class="button" value="Cancel" />
          </div>
        </form>';
        return $form;
      }  
      
      
      //========================================//
      //== Insert / Update a Row in the Table ==//
      //========================================//
      public function save(){
        //Get Values From Post
        $id = htmlentities($_POST["video_id"],ENT_QUOTES);
        $url = htmlentities($_POST["video_url"],ENT_QUOTES);
        $title = htmlentities($_POST["video_title"],ENT_QUOTES);
        
        if(!empty($url)){
          if (!$id) {	//Creation
            $sql = "INSERT INTO ".table_name." (`video_url`,`video_title`) VALUES ('$url','$title')";
            if(mysql_query($sql)) { return mysql_insert_id(); } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
          }
          else {		//Update
            $modifs="";
            if(!empty($url)){ $modifs.=" `video_url` = '$url',"; }
            if(!empty($title)){ $modifs.=" `video_title` = '$title',"; }
            $sql = "UPDATE ".table_name." SET ".substr($modifs,0,-1)." WHERE video_id = $id";
            if(mysql_query($sql)) { return $id; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
          } 
        }
      }
      
      //==========================================//
      //============ Delete a Video ==============//
      //==========================================//
      public function delete(){
    	$sql = "DELETE FROM ".table_name." WHERE video_id = ".(int)$this->id;
    	if(mysql_query($sql)) { return true; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }  
      }
    
    
    //=============================================================================================================================//  
    //========================================= Examples Used in the Demonstration ================================================//
    //=============================================================================================================================//
    
    
      //=======================================//
      //========== Create the Table ===========//
      //=======================================//
      public function createVideoTable(){
        $sql='CREATE TABLE IF NOT EXISTS `'.table_name.'` (
        `video_id` int(11) NOT NULL auto_increment,
        `video_url` varchar(255) default NULL,
        `video_title` varchar(255) default NULL,
        PRIMARY KEY  (`video_id`)
        )';
        if(mysql_query($sql)) { return true; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
      }
      
      //==============================================//
      //==> Display the video Thumbnails on a page <==//
      //==============================================//
      public function getThumbnailsList(){
        
        $thumbdom="<ul>"; $playerdom="";
        
        //Get The videos from DB
        $videolist = MyVideo::getrecords();
        
        //Loop Through Them
        if(!empty($videolist)){foreach($videolist as $video){
          
          //Get YouTube Id
          $youtubeid = str_replace("watch?v=","",end(explode("/",$video[video_url])));
          $youtubeid = reset(explode("&",$youtubeid));
          
          //Youtube video File + Youtube video Thumbnail
          $thumb = "http://img.youtube.com/vi/$youtubeid/default.jpg";
          $file = "http://www.youtube.com/v/$youtubeid";
          
          //Build Up your list of video
          $thumbdom.='<li>
          <a class="fancy" href="#video'.$video[video_id].'" title="'.$video[video_title].'">
            <img src="'.$thumb.'" alt="'.$video[video_title].'" />
          </a>
          </li>';
          
          //Also adds the corresponding player for the video
          $playerdom.='<div class="video_player_wrap" id="video'.$video[video_id].'">
            <embed style="width:400px;height:350px" src="'.$file.'&autoplay=1&hl=en&fs=1
            &rel=0&color1=0x3a3a3a&color2=0x999999" 
            type="application/x-shockwave-flash" allowscriptaccess="always" 
            allowfullscreen="true" width="320" height="265"></embed>
          </div>'."\n";
        }}
        $thumbdom.="</ul>";
        $dom='<div id="thumbnailscontainer">'.$thumbdom.'</div>
        <div id="playercontainer">'.$playerdom.'</div>';
        return $dom;
      }
      
      
      //====================================================//
      //==> Lists the videos for administration purposes <==//
      //====================================================//
      public function getAdminList(){
        $admindom="<ul>";
    
        //Get the videos From DB
        $videolist = MyVideo::getrecords();
        if(!empty($videolist)){foreach($videolist as $record){
        //Build the Admin List of videos
        $admindom.='
        <li id="MyVideo_'.$record[video_id].'">
          <span>
            <a href="'.$record[video_url].'" target="_blank" title="'.$record[video_url].'">
              '.$record[video_title].'
            </a> | 
          </span>
          <a class="editvideolink" href="#">Edit</a>
          <a class="deletevideolink" href="#" >Delete</a>
        </li>';
        }}
        $admindom.="</ul>";
        return $admindom;
      }
    
    
      //====================================================//
      //====> Generates the markup for the public page <====//
      //====================================================//  
      public function getPublicSide(){
      	echo MyVideo::getThumbnailsList();
      }
    
    
      //====================================================//
      //=====> Generates The markup for the Admin Page <====//
      //====================================================//  
      public function getAdminSide(){	
        //Table Creation (Uncomment to create the SQL Table)
        //MyVideo::createVideoTable();
    
        //Little API to Manage the posted data
        if(!empty($_POST)){
          MyVideo::POSTManager();
        } 
        if($_POST['ajaxrequest']!=1){ //If not an ajax request
          //Get the Admin Form and the video List
          echo'
          <div id="adminwrap">
            <div id="addrecordwrap">
              <a href="#">Add a new Video</a>
            </div>
            <div id="recordform">';
              //Admin Form
              echo MyVideo::getVideoForm(0,"/resources/video_manager","post");
            echo'
            </div>
            <div id="recordlist">
              <h3>Your Videos:</h3>';
              //Video List
              echo MyVideo::getAdminList();	
            echo'</div>
          </div>';
         }
      }
    
    
      //=====================================================================//
      //==> Order an insert / update or delete based on the posted values <==//
      //=====================================================================//  
      public function POSTManager(){
        //What Are We Going to do?
        $action = htmlentities($_POST['todo'],ENT_QUOTES);
        switch($action){
          //Add or Edit a Video
          case "savevideo": MyVideo::save(); 
            echo'<div class="feedback">Video Saved With Success</div>'; 
          break;
          
          //Remove a video
          case'delvideo':
            $recordid = htmlentities($_POST['recordid'],ENT_QUOTES);
            if(!empty($recordid)){
              $record = new MyVideo($recordid);
              $record->delete();
            }
          break;	
          
          //Load A video and return JSON
          case 'loadvideo':
            $recordid = htmlentities($_POST['recordid'],ENT_QUOTES);
            if(!empty($recordid)){
              $record = MyVideo::load($recordid);
              if(!empty($record)){
                echo'
                {
                "video_id" : "'.$recordid.'",
                "video_title" : "'.$record->title.'",
                "video_file" : "'.$record->url.'"
                }';
              }
            }
          break;				
          default: break;
        }  
      }
      
    //=============================================================================================================================//
    
    }
    
    ?>
  2. Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!

    lima-city: Gratis werbefreier Webspace für deine eigene Homepage

  3. mamam schrieb:
    ... Könnt ihr sagen wie ich die Datenbank machen muss
    gar nicht ;) sehe dir die zeilen ab 137 an (du solltest überhaupt - bevor du mit einem fremdprogramm irgendwas machst - die materie genau ansehen! sprich: dich in den sourcecode einlesen, so dass du es verstehst, was da los ist).
    Die Datenverbindung machen muss.?
    auch das ist mit lesen verbunden: Verwaltung

    (hier nochmals dein code durchnummeriert! also ab zeile 137:
    <?php
    
    define("table_name","myvideos");
    
    class MyVideo {
    
      //=======================================//
      //==========> Class Variables <==========//
      //=======================================//
      private $id;		//Id of the Video
      private $url;		//YouTube Url
      private $title;	//Video Title
    
    
    //=======================================================================================//
    //================================= Core Methods ========================================//
    //=======================================================================================//
      
    
      //=======================================//
      //============> Constructor <============//
      //=======================================//
      public function __construct($id=0,$url="",$title="")
      {
        $this->id=$id;
        $this->url = $url;
        $this->title = $title;
      }
      
      
      //=======================================//
      //======> Load a Video Via its ID <======//
      //=======================================//
      public function load($id){
        //Select the Video Information from DB
        $sql="SELECT * FROM ".table_name." WHERE video_id = $id LIMIT 1";
        $result=array(); $video = new MyVideo();
        $req = mysql_query($sql) or die("Erreur SQL !<br>".$sql."<br>".mysql_error());
        
        //Assign those Infomation to a MyVideo Object
        while($data= mysql_fetch_assoc($req)) {
          $MyVideo->id = $data[video_id];
          $MyVideo->url = $data[video_url];
          $MyVideo->title = $data[video_title];
        }
        
        return $MyVideo;    
      }
    
    
      //=======================================//
      //======> Get Video List From DB <=======//  
      //=======================================//
      public function getrecords()
      {
        //Select all videos from DB
        $sql="SELECT * FROM ".table_name."";
        $result=array();
        $req = mysql_query($sql) or die("SQL Error!<br>".$sql."<br>".mysql_error());
        while($data= mysql_fetch_assoc($req)) {
          $result[]=$data;
        }
        return $result;
      }  
      
      
      //==========================================//
      //== Display the form to add/edit a video ==//
      //==========================================//
      public function getVideoForm($videoid=0,$action="", $method="post"){
        //Load A Video if $videoid (Used to edit an existing video)
        if( (!empty($videoid)) && (is_numeric($videoid)) ){ 
          $video = MyVideo::load($videoid); 
        } else { 
          $video = new MyVideo(); 
        }
        
        //The Form Markup (Video Url, + Video Title)
        $form='<form action="'.$action.'" method="'.$method.'">
          <div class="regrow">
            <label class="inside" for="video_url">YouTube url:</label>
            <input type="text" name="video_url" class="text" value="'.$video->url.'" />
          </div>
          <div class="regrow">
            <label class="inside" for="video_title">Video Title:</label>
            <input type="text" name="video_title" class="text" value="'.$video->title.'" />
          </div>
          <div class="regrow">
            <input type="hidden" name="video_id" value="'.$video->id.'" />
            <input type="hidden" name="todo" value="savevideo" />
            <input type="submit" class="button" value="Send" /> 
            <input id="cancelctcform" type="button" class="button" value="Cancel" />
          </div>
        </form>';
        return $form;
      }  
      
      
      //========================================//
      //== Insert / Update a Row in the Table ==//
      //========================================//
      public function save(){
        //Get Values From Post
        $id = htmlentities($_POST["video_id"],ENT_QUOTES);
        $url = htmlentities($_POST["video_url"],ENT_QUOTES);
        $title = htmlentities($_POST["video_title"],ENT_QUOTES);
        
        if(!empty($url)){
          if (!$id) {	//Creation
            $sql = "INSERT INTO ".table_name." (`video_url`,`video_title`) VALUES ('$url','$title')";
            if(mysql_query($sql)) { return mysql_insert_id(); } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
          }
          else {		//Update
            $modifs="";
            if(!empty($url)){ $modifs.=" `video_url` = '$url',"; }
            if(!empty($title)){ $modifs.=" `video_title` = '$title',"; }
            $sql = "UPDATE ".table_name." SET ".substr($modifs,0,-1)." WHERE video_id = $id";
            if(mysql_query($sql)) { return $id; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
          } 
        }
      }
      
      //==========================================//
      //============ Delete a Video ==============//
      //==========================================//
      public function delete(){
    	$sql = "DELETE FROM ".table_name." WHERE video_id = ".(int)$this->id;
    	if(mysql_query($sql)) { return true; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }  
      }
    
    
    //=============================================================================================================================//  
    //========================================= Examples Used in the Demonstration ================================================//
    //=============================================================================================================================//
    
    
      //=======================================//
      //========== Create the Table ===========//
      //=======================================//
      public function createVideoTable(){
        $sql='CREATE TABLE IF NOT EXISTS `'.table_name.'` (
        `video_id` int(11) NOT NULL auto_increment,
        `video_url` varchar(255) default NULL,
        `video_title` varchar(255) default NULL,
        PRIMARY KEY  (`video_id`)
        )';
        if(mysql_query($sql)) { return true; } else { die("SQL Error!<br>".$sql."<br>".mysql_error()); return false; }
      }
      
      //==============================================//
      //==> Display the video Thumbnails on a page <==//
      //==============================================//
      public function getThumbnailsList(){
        
        $thumbdom="<ul>"; $playerdom="";
        
        //Get The videos from DB
        $videolist = MyVideo::getrecords();
        
        //Loop Through Them
        if(!empty($videolist)){foreach($videolist as $video){
          
          //Get YouTube Id
          $youtubeid = str_replace("watch?v=","",end(explode("/",$video[video_url])));
          $youtubeid = reset(explode("&",$youtubeid));
          
          //Youtube video File + Youtube video Thumbnail
          $thumb = "http://img.youtube.com/vi/$youtubeid/default.jpg";
          $file = "http://www.youtube.com/v/$youtubeid";
          
          //Build Up your list of video
          $thumbdom.='<li>
          <a class="fancy" href="#video'.$video[video_id].'" title="'.$video[video_title].'">
            <img src="'.$thumb.'" alt="'.$video[video_title].'" />
          </a>
          </li>';
          
          //Also adds the corresponding player for the video
          $playerdom.='<div class="video_player_wrap" id="video'.$video[video_id].'">
            <embed style="width:400px;height:350px" src="'.$file.'&autoplay=1&hl=en&fs=1
            &rel=0&color1=0x3a3a3a&color2=0x999999" 
            type="application/x-shockwave-flash" allowscriptaccess="always" 
            allowfullscreen="true" width="320" height="265"></embed>
          </div>'."\n";
        }}
        $thumbdom.="</ul>";
        $dom='<div id="thumbnailscontainer">'.$thumbdom.'</div>
        <div id="playercontainer">'.$playerdom.'</div>';
        return $dom;
      }
      
      
      //====================================================//
      //==> Lists the videos for administration purposes <==//
      //====================================================//
      public function getAdminList(){
        $admindom="<ul>";
    
        //Get the videos From DB
        $videolist = MyVideo::getrecords();
        if(!empty($videolist)){foreach($videolist as $record){
        //Build the Admin List of videos
        $admindom.='
        <li id="MyVideo_'.$record[video_id].'">
          <span>
            <a href="'.$record[video_url].'" target="_blank" title="'.$record[video_url].'">
              '.$record[video_title].'
            </a> | 
          </span>
          <a class="editvideolink" href="#">Edit</a>
          <a class="deletevideolink" href="#" >Delete</a>
        </li>';
        }}
        $admindom.="</ul>";
        return $admindom;
      }
    
    
      //====================================================//
      //====> Generates the markup for the public page <====//
      //====================================================//  
      public function getPublicSide(){
      	echo MyVideo::getThumbnailsList();
      }
    
    
      //====================================================//
      //=====> Generates The markup for the Admin Page <====//
      //====================================================//  
      public function getAdminSide(){	
        //Table Creation (Uncomment to create the SQL Table)
        //MyVideo::createVideoTable();
    
        //Little API to Manage the posted data
        if(!empty($_POST)){
          MyVideo::POSTManager();
        } 
        if($_POST['ajaxrequest']!=1){ //If not an ajax request
          //Get the Admin Form and the video List
          echo'
          <div id="adminwrap">
            <div id="addrecordwrap">
              <a href="#">Add a new Video</a>
            </div>
            <div id="recordform">';
              //Admin Form
              echo MyVideo::getVideoForm(0,"/resources/video_manager","post");
            echo'
            </div>
            <div id="recordlist">
              <h3>Your Videos:</h3>';
              //Video List
              echo MyVideo::getAdminList();	
            echo'</div>
          </div>';
         }
      }
    
    
      //=====================================================================//
      //==> Order an insert / update or delete based on the posted values <==//
      //=====================================================================//  
      public function POSTManager(){
        //What Are We Going to do?
        $action = htmlentities($_POST['todo'],ENT_QUOTES);
        switch($action){
          //Add or Edit a Video
          case "savevideo": MyVideo::save(); 
            echo'<div class="feedback">Video Saved With Success</div>'; 
          break;
          
          //Remove a video
          case'delvideo':
            $recordid = htmlentities($_POST['recordid'],ENT_QUOTES);
            if(!empty($recordid)){
              $record = new MyVideo($recordid);
              $record->delete();
            }
          break;	
          
          //Load A video and return JSON
          case 'loadvideo':
            $recordid = htmlentities($_POST['recordid'],ENT_QUOTES);
            if(!empty($recordid)){
              $record = MyVideo::load($recordid);
              if(!empty($record)){
                echo'
                {
                "video_id" : "'.$recordid.'",
                "video_title" : "'.$record->title.'",
                "video_file" : "'.$record->url.'"
                }';
              }
            }
          break;				
          default: break;
        }  
      }
      
    //=============================================================================================================================//
    
    }
    allerdings die zeile 141 musst du bei lima anpassen:
    141 |    $sql='CREATE TABLE IF NOT EXISTS `db_xxxxxx_n.'.table_name.'` (
    wobei 'xxxxxx' ist dein 6stelliger usernummer und n=1 o. n>1 (wenn du mehrere dbs hast).

    Beitrag zuletzt geändert: 18.6.2013 0:03:42 von czibere
  4. Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!

    lima-city: Gratis werbefreier Webspace für deine eigene Homepage

Dir gefällt dieses Thema?

Über lima-city

Login zum Webhosting ohne Werbung!