我仍在学习有关 PHP 的更多有趣细节。示例:从 MySQL 迁移到 MySQLi。我目前正在做的是尝试输入这样的内容:http ://music.daum.net/artist/main?artist_id=2289
从我通过切分网址从分页中学到的知识:
- 主要的?
 - 艺术家 ID=
 - 2289
 
我怎样才能制作这样的页面?我有 2 个部分可用,并会在弄清楚这一点时制作其他部分。
- 艺术家信息(可作为testhub-artist.php 获得)
 - 专辑(可作为testhub-artistalbum.php 获得)
 - 音乐视频
 - 照片部分
 
我希望在制作页面时更容易,而不是为每个人制作单独的文件夹。
我的网址是:“../artist/detail?artist_id=#”
这是艺术家页面的顶部。
<?php
//Connect to ...
include "testhub-artist.php";
include "testhub-artistalbum.php";
?>
testhub-artist.php
<?php
//Connect to database
include "mysqli_connect.php";
// Construct our join query
$sql = "SELECT * FROM individuals WHERE soloID = 1";
// Create results
$result = mysqli_query($link, $sql);
// Checking if query is successful
if($result){
// Print out the contents of each row into a table 
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
// If else states on each variable
    if ($profilepic = $row['profilepic']){
        $profilepic = $row['profilepic'];
    }else{
        $profilepic = "DamjuNoImage";
    }
    if ($engname = $row['engname']){
        $engname = $row['engname'];
    }else{
        $engname = "Unknown";
    }
    if ($korname = $row['korname']){
        $korname = $row['korname'];
    }else{
        $korname = "Unknown";
    }
    if ($engbn = $row['engbn']){
        $engbn = $row['engbn'];
    }else{
        $engbn = "Unknown";
    }
    if ($korbn = $row['korbn']){
        $korbn = $row['korbn'];
    }else{
        $korbn = "Unknown";
    }
    if ($dateofbirth = $row['dateofbirth']){
        $dateofbirth = $row['dateofbirth'];
    }else{
        $dateofbirth = "Unknown";
    }
    if ($occupation = $row['occupation']){
        $occupation = $row['occupation'];
    }else{
        $occupation = "Unknown";
    }
    if ($debut = $row['debut']){
        $debut = $row['debut'];
    }else{
        $debut = "Unknown";
    }
    if ($recordlabel = $row['recordlabel']){
        $recordlabel = $row['recordlabel'];
    }else{
        $recordlabel = "Unknown";
    }
    if ($officialsite = $row['officialsite']){
        $officialsite = $row['officialsite'];
    }else{
        $officialsite = "#";
    }
    if ($sitename = $row['sitename']){
        $sitename = $row['sitename'];
    }else{
        $sitename = "Unknown";
    }
} // End of while statement
}else{
    $engname = "Unknown";
    $korname = "Unknown";
    $engbn = "Unknown";
    $korbn = "Unknown";
    $dateofbirth = "Unknown";
    $occupation = "Unknown";
    $debut = "Unknown";
    $recordlabel = "Unknown";
    $officialsite = "#";
    $sitename = "Unknown";
} // End of If statement
// Free result set
//mysqli_free_result($result);
?>
testhub-artistalbum.php
<?php
//connect to db
include "mysqli_connect.php";
//check for a page number. If not, set it to page 1
if (!(isset($_GET['albumpage']))){
    $albumpage = 1;
}else{
    $albumpage = $_GET['albumpage'];
}
//query for record count to setup pagination
$sqli = "SELECT * FROM albums WHERE soloID = 3";
$album_data = mysqli_query($link, $sqli);
$album_rows = mysqli_num_rows($album_data); 
//number of photos per page
$album_pagerows = 4; 
//get the last page number
$last_album = ceil($album_rows/$album_pagerows); 
//make sure the page number isn't below one, or more than last page num
if ($albumpage < 1){
    $albumpage = 1;
}elseif ($albumpage > $last_album){
    $albumpage = $last_album;
}
//Set the range to display in query
$max_album = 'limit ' .($albumpage - 1) * $album_pagerows .',' .$album_pagerows;
//get all of the photos
$albumList = "";
$sqli2 = "SELECT * FROM albums WHERE soloID = 3 ORDER BY releasedate DESC $max_album";
$album_sql = mysqli_query($link, $sqli2);
//check for photos
$albumCount = mysqli_num_rows($album_sql);
if ($albumCount > 0){
    while($album_rows = mysqli_fetch_array($album_sql)){
    $albumID = $album_rows["albumID"];
    $albumpic = $album_rows["albumpic"];
    $title = $album_rows["albumTitle"];
    $releasedate = $album_rows["releasedate"];
    $page = $album_rows["page"];
    $albumList .= '
      <li class="albumthumb">
         <a href="' . $page . '" title="' . $title . '"><img class="profile" src="../albums/album_th/' . $albumpic . '.jpg" alt="' . $albumpic . '" width="120" height="120" border="0" /><p class="datatitle">' . $title . '</p></a><p class="data-releasedate">' . $releasedate . '</p>
       </li>
                  ';
    }
}else{
    $albumList = "There are no available albums at this time!";
}
//mysql_close();
?>
抱歉没有解释清楚。我希望在制作像 url 这样的个人资料页面时能够使用分页。我想使用url中的数字来更改sql代码中的id(soloID)。
节省时间的好主意,对吧?MySQLi 每次我看到它都会变得更容易。
谢谢你。
已更改 2012 年 5 月 31 日下午 5:44 CT
$artist = $_GET['artist_id']
进入
    if(is_numeric($_GET['artist_id'])){
    $artist = $_GET['artist_id'];
}else{
    $artist = 1;
}