我有兩個MySQL列表的列數。下面的表格結構中給出,一個PHP函數來處理不同的MySQLi select語句
1.pictures
postedON
字幕
imageName
thumbName
imageLocation
thumbLocation
2.Videos
postedOn
類別
鏈接
我正在使用以下PHP函數從數據庫中使用select命令獲取數據。
function select($table){
if($this->db_connection){
$query = 'SELECT * FROM '. $table;
$result = mysqli_query($this->db_connection,$query) or die($this->db_connection->error);
//print_r($result);
//echo "Affected rows: " . mysqli_affected_rows($this->db_connection);
//var_dump($result);
echo "<table>";
echo "<tr>";
echo "<th>Date Posted</th>";
echo "<th>Category</th>";
echo "<th>Link</th>";
echo "</tr>";
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td>" . $row['postedOn'] . "</td>";
echo "<td>".$row['category']. "</td>";
echo "<td><a href=".$row['link'] .">" . $row['link'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}else{
echo "db_connection is = " . $this->db_connection;
}
}
}
使用此功能,你可以看到的問題,它只能服務於只有一個表,不是動態的。有人可以請解釋一下,只使用一個PHP函數來動態從不同列數的表中獲取數據的方式嗎?由於
鏈接和圖片怎麼樣? –