亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP開發(fā)實作下載次數(shù)統(tǒng)計功能模組(一)

先把連接資料庫程式碼放入conn.php檔案中方便使用require ?'conn.php' 呼叫。

?require 語句用於在執(zhí)行流程中插入寫在其他檔案中的有用的程式碼

以下是資料庫檔案conn.php

<?php
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost','username','password','test');
mysqli_set_charset($link, "utf8");

if(!$link)
{
  die("連接失敗:".mysqli_connect_error());
}
header("Content-Type: text/html; charset=utf-8");
?>

建立一個是filelist.php,用來讀取mysql資料表中的數(shù)據(jù),並輸出為JSON格式的資料用來給前臺html頁面呼叫

先使用?require 語句呼叫conn.php資料庫文件,透過SQL語句中的SELECT讀取出資料庫downloads表中的所有資料

把資料表中的id, filename等while循環(huán)輸出保存到一個數(shù)組$data[]中,然後把$data[]數(shù)組中的數(shù)據(jù)echo為JSON格式,方便

前臺html頁面呼叫。

filelist.php檔案內(nèi)容如下:

<?php
require 'conn.php';

$result = mysqli_query($link,"SELECT * FROM downloads");
   //返回的記錄數(shù)
if(mysqli_num_rows($result)){  //mysqli_num_rows() 函數(shù)返回結(jié)果集中行的數(shù)量
   while($row=mysqli_fetch_assoc($result)){
      $data[] = array(
         'id' => $row['id'],
         'file' => $row['filename'],
         'downloads'=> $row['downloads']
      );
   }
   echo json_encode($data);  //json_encode—返回一個值的JSON格式
}
?>

mysqli_num_rows()?函數(shù)傳回結(jié)果集中行的數(shù)量

json_encode—傳回一個值的JSON格式

繼續(xù)學(xué)習(xí)
||
<?php require 'conn.php'; $result = mysqli_query($link,"SELECT * FROM downloads"); //返回的記錄數(shù) if(mysqli_num_rows($result)) { //mysqli_num_rows() 函數(shù)返回結(jié)果集中行的數(shù)量 while($row=mysqli_fetch_assoc($result)) { $data[] = array( 'id' => $row['id'], 'file' => $row['filename'], 'downloads'=> $row['downloads'] ); } echo json_encode($data); //json_encode—返回一個值的JSON格式 } ?>