![](/img/trans.png)
[英]Php : How can I make values that have been saved in a table appear on the page as being checked?
[英]Using PHP how can i display images which have been saved in SQL as a image path
我正在嘗試從SQL數據庫中檢索使用映像路徑保存的映像。 圖像保存在服務器上。 當我檢索圖像時,什么也不會返回。
if(isset($_GET))
{
include_once "mysql_connect.php";
$text = $_GET['text'];
if($text=="")
{
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '1'")
or die(mysql_error());
while( $rows=mysql_fetch_array($query) )
{
$search[] = $rows[0];
}
$result = array();
$result["result"] = 500;
$result["message"] = "Database Read Successfully";
$result["rows"] = $search;
echo json_encode($result);
exit;
代碼示例用於用戶無需輸入值的搜索。 在SQL語句“ URL”內是存儲圖像路徑的字段。圖像路徑值是完整的URL http://example.com/images/test.jpg並存儲為VARCHAR(200)。 任何意見,將不勝感激
您的代碼不能正常工作。 您沒有關閉if
語句。
另外,當$text
不為空時,您將對數據庫沒有任何查詢...
您將需要以下內容:
if($text==""){
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '1'")
or die(mysql_error());
}
//when $text is not empty...
else{
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '".$text."'")
or die(mysql_error());
}
while( $rows=mysql_fetch_array($query)){
$search[] = $rows[0];
}
順便說一下,嘗試使用PDO代替mysql_query
,這最后一個已過時,並且容易受到SQL注入的攻擊。
圖像在服務器中,因此路徑僅在服務器上起作用。
如果您執行以下操作:
echo json_encode($result);
我想您正在將此信息返回給客戶端,如果要顯示它們,圖像路徑在那里沒有任何值!
如果要向用戶顯示圖像,則需要使用HTML img
標簽,並用路徑FROM THE SERVER填充src屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.