我有两个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函数来动态从不同列数的表中获取数据的方式吗?由于
链接和图片怎么样? –