2016-12-12 6 views
-1

私は電子音楽PHP Webベースのアプリケーションを作成したいと思います。私はforllowingを達成したいです: 1.ダウンロードボタンをクリックしてください 2.そのファイルのダウンロード数は、音楽の1つの 次のコードショーのリストだけ増分されなければならないが、私は「ダウンローダ」ボタンをclikingにダウンロードを試みたコードの新しいリリースやトップダウンロードMp3ファイル形式のmysql DBをダウンロードし、クリックあたりのダウンロード数を増やす

<?php 
    $hostname_conn = "localhost"; 
$database_conn = "e-music"; 
$username_conn = "root"; 
$password_conn = ""; 
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error()); 

    $sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3"; 
    $Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error()); 
    $sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3"; 
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error()); 
?>  
<table align="center" class="table table-striped table-hover "> 
     <thead> 
      <tr> 
       <th colspan="3" align="center"> <h3>New Releases </h3></th> 
      </tr> 
     </thead> 
     <tbody> 
     <?php while ($row=mysqli_fetch_assoc($Result)) { ?> 
      <tr> 


       <td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" > 
       </div> 
        <label> Artist: <?php echo $row['artist_name'] ?></label> <br/> 
       <label> Title: <?php echo $row['m_title'] ?></label> <br/> 
       <label>Category: Wakoin <?php echo $row['cat_name'] ?></label> 
       </td> 
       <td> 

       <a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a> 


       </td> 
       <td class="col-md-2"> 
        Format:<?php echo $row['m_format']; ?> 
       </td> 
       <td class="col-md-2"> 
        File Size: <?php echo round($row['size']/1048576,2); ?> MB 
       </td> 
      </tr> 
      <?php 
      } 
      ?> 
     </tbody> 

    </table> 
    <table align="center" class="table table-striped table-hover"> 
     <thead> 
      <tr> 
       <th colspan="3" align="center"> <h3>Top Downloads </h3></th> 
      </tr> 
     </thead> 
     <tbody> 
     <?php while ($row=mysqli_fetch_assoc($Result1)) { ?> 
      <tr> 
       <td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" > 
       </div> 
        <label> Artist: <?php echo $row['artist_name'] ?></label> <br/> 
       <label> Title: <?php echo $row['m_title'] ?></label> <br/> 
       <label>Category: Wakoin <?php echo $row['cat_name'] ?></label> 
       </td> 

       <td class="col-md-2"> 
        <a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a> 


       </td> 
       <td class="col-md-2"> 
        Format: <?php echo $row['m_format']; ?> 
       </td> 
       <td> 
        File Size :<?php echo round($row['size']/1048576,2); ?> MB 
       </td> 
      </tr> 
      <?php 
      } 
      ?> 
     </tbody> 

    </table> 

、すなわちdownload.phpファイルにリダイレクトされます:

$hostname_conn = "localhost"; 
$database_conn = "e-music"; 
$username_conn = "root"; 
$password_conn = ""; 
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error()); 

    $did=$_GET['did']; 

$sql="SELECT target from music where mid='$did'"; 
    $Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error()); 
$row = mysqli_fetch_assoc($Result); 
// the target filed contains the directory and file name of the file to be downloaded e.g uploads/Akon_Sorry Blame.mp3 
echo "<a href=". $row['target'] ." > download</a>"; 
$sql1="update music set download=download+1 where mid='$did"; 
$Result= mysqli_query($conn,$sql1) or die('Cannot Increment number of downloads' . mysqli_error()); 
+1

クエリでエラーが発生しました 'updte'が' update'になっています – rafwlaz

+0

ここに間違いました...私のファイルはダウンロードされていません – Othman

+0

'affected_row s() '。 –

答えて

0

私のプロジェクトの研究の後、私はajaxを使って自分の問題を解決することができます。ここで私は

//index page 
<!DOCTYPE html> 
<html> 
<head> 
<title>E-music</title> 
<link href="includes/Style.css" rel="stylesheet" type="text/css"/> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> 
    <script src="jQuery/jquery-1.11.1.min.js" type="text/javascript"></script> 
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript"></script> 
    <script src="bootstrap-3.3.7-dist/js/site.js" type="text/javascript"></script> 


<?php 
    require_once("includes/connection.php"); 
    $sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3"; 
    $Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error()); 
    $sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3"; 
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error()); 
?> 


<div id="nav"> 
<a href="SearchMusic.php" class="btn btn-primary">Search For Music Audio</a> 
<p>Wakokin Hausa Na Gargajiya 
</p> 
</div> 

<div id="section"> 
<table align="center" class="table table-striped table-hover "> 
    <thead> 
     <tr> 
      <th colspan="3" align="center"> <h3>New Releases </h3></th> 
     </tr> 
    </thead> 
    <tbody> 
    <?php while ($row=mysqli_fetch_assoc($Result)) { ?> 
     <tr> 
      <td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" > 
      </div> 
       <label> Artist: <?php echo $row['artist_name'] ?></label> <br/> 
      <label> Title: <?php echo $row['m_title'] ?></label> <br/> 
      <label>Category: Wakoin <?php echo $row['cat_name'] ?></label> 
      </td> 
      <td> 
       <a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a> 

      </td> 
      <td class="col-md-2"> 
       Format:<?php echo $row['m_format']; ?> <br> 

       Total Download: <?php echo $row['downloads']; ?> 
      </td> 
      <td class="col-md-2"> 
       File Size: <?php echo round($row['size']/1048576,2); ?> MB 
      </td> 
     </tr> 
     <?php 
     } 
     ?> 
    </tbody> 

</table> 
<table align="center" class="table table-striped table-hover"> 
    <thead> 
     <tr> 
      <th colspan="3" align="center"> <h3>Top Downloads </h3></th> 
     </tr> 
    </thead> 
    <tbody> 
    <?php while ($row=mysqli_fetch_assoc($Result1)) { ?> 
     <tr> 
      <td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" > 
      </div> 
       <label> Artist: <?php echo $row['artist_name'] ?></label> <br/> 
      <label> Title: <?php echo $row['m_title'] ?></label> <br/> 
      <label>Category: Wakoin <?php echo $row['cat_name'] ?></label> 
      </td> 

      <td class="col-md-2"> 
       <a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a> 

      </td> 
      <td class="col-md-2"> 
       Format: <?php echo $row['m_format']; ?> 
       Total Download: <?php echo $row['downloads']; ?> 
      </td> 
      <td> 
       File Size :<?php echo round($row['size']/1048576,2); ?> MB 
      </td> 
     </tr> 
     <?php 
     } 
     ?> 
    </tbody> 

</table> 
</div> 

がdatabae更新

<?php 
require_once("includes/connection.php"); 

    $id = $_POST["id"]; 

    $Result= mysqli_query($conn,"SELECT downloads as total FROM music WHERE mid='$id'"); 
    $Res = mysqli_fetch_assoc($Result); 
    $re = $Res['total'] + 1; 
    $updateCount = mysqli_query($conn, "UPDATE music SET downloads= '$re' WHERE mid=$id "); 

?> 
を処理するための

$(function() { 


    $(".dload").click(function(){ 

     var id = $(this).attr("d");  

     $.ajax({ 
       type: "POST", 
       url: "count.php", 
       data: {id:id}, 
       success: function(info) 
       { 

       }, 
       error: function(){ 

       } 

      }); 
    }); 

    }); 

//conut.phpをダウンロードインクリメントを処理するためのAJAXファイルを//Site.js私の目標を達成するために使用されるコードです

関連する問題