我想用php獲取數(shù)據(jù)庫里的圖片路徑之后,用img標(biāo)簽顯示出來但是并沒有成功,也沒有報錯。下面是php代碼:`<?php
/* 包含連接數(shù)據(jù)庫文件 */
include_once("../config/conn.php");
/* 定義查詢語句 */
$sql = "select URL from ImgURL";
/* 獲取返回結(jié)果 */
$result = mysqli_query($conn, $sql);
/* 包含index.php文件 */
include('../index.html');`
下面是HTML部分代碼:
<a >
<img alt="" src="<?php echo($result);?>" width="244" />
</a>
下面是數(shù)據(jù)庫中的數(shù)據(jù):我直接用數(shù)據(jù)庫中的路徑是可以顯示的,但是如果我用PHP獲取數(shù)據(jù)庫里的路徑之后為什么不顯示圖片呢?求解答,謝謝!
下面是最新遇到的問題:PHP代碼已經(jīng)更改了,并將查詢結(jié)果儲存到了數(shù)組當(dāng)中,查詢結(jié)果是可以成功打印出來的:
<?php
/* 包含連接數(shù)據(jù)庫文件 */
include_once("./config/conn.php");
/* 定義查詢語句 */
$sql = "select URL from ImgURL";
/* 獲取返回結(jié)果 */
$result = mysqli_query($conn, $sql);
$rows=array();
if ($result)
{
if ($result->num_rows>0)
{
$i=0;
while ($row = $result->fetch_array()) {
//print_r($rows);
array_push($rows,$row['URL']);
// echo "<BR>".$rows[$i];
// $i=$i+1;
}//end while()
}else{
echo "<BR>查詢結(jié)果為空!";
}//end if()
}else{
echo "<BR>查詢失??!";
}
$rows數(shù)組打印結(jié)果如下:但是,頁面渲染出來之后會,img標(biāo)簽的src為unknown,HTML代碼如下:
<a ><img alt=""
src="<?php $rows[2]?>" width="244" /></a>
- 8 回答
- 0 關(guān)注
- 1485 瀏覽
添加回答
舉報
0/150
提交
取消