我想創建一個基於行值的鏈接,並且 - 更重要的是,添加一個變量 - 如果行爲空,那麼這個文本...如果行有一些值,則顯示此... 。mysqli根據行創建鏈接
//我需要得到這個DISPLAY:
//如果行賽季是空的,生成的鏈接必須是
// web.com/MOVIES/".$row["title_id 「]。」
//如果賽季有一定的價值,那麼鏈接必須是://web.com/SERIES/".$row["title_id"]."/SEASON/".$row["season「] 「/劇集/".$行[」 插曲 「]」。
這是基本代碼。
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, type, label, title_id, season, episode, approved FROM links order by id desc LIMIT 30 OFFSET 50";
$result = $last_id = $conn->query($sql);
if ($result->num_rows > 0)
{
echo "<table><tr><th>ID</th><th>Label</th><th>URL</th><th>Season</th><th>Episode</th><th>Approved</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["label"]."</td>";
// --------------------------------------------------------------
echo "<td><a href='http://web.com/(VARIABLES HERE)'>";
echo " ".$row["title_id"]."</a></td>";
// --------------------------------------------------------------
//I NEED TO GET THIS DISPLAY:
// if row season is empty, the resulting link must be
// web.com/MOVIES/".$row["title_id"]."
// if row season have some value, then the link must be:
//web.com/SERIES/".$row["title_id"]."/SEASON/".$row["season"]."/EPISODE/".$row["episode"]."
// -----------------------------------------
echo "<td>".$row["season"]."</td><td>".$row["episode"]."</td><td>".$row["approved"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
*「這是基本代碼。」* - 問題是/? –
順便說一句,你正在使用[保留MySQL關鍵字](https://dev.mysql.com/doc/refman/5.5/en/keywords.html)和[你沒有看到語法***錯誤* **這是扔你。](http://php.net/manual/en/mysqli.error.php) –
[使用***三元***運營商](http://php.net/manual/ en/language.operators.comparison.php),只是爲了回答嵌入代碼中的問題。好東西,我發現,* eh?* –