2013-07-20 41 views
0

我有​​數據庫鏈接無法使用

綠色標誌去一個問題,旁邊的圖片是爲了訪問保存在我的數據庫中的促銷活動現場。但它會在新選項卡中加載相同的頁面。

我對這個代碼是:

<a href="<?php echo $data['promo_link']; ?>" target="_blank"><img alt="" title="" src="GO.png" height="50" width="50" align="right" /></a> 

任何想法,爲什麼它不工作?

如果您需要我的任何頁面的任何代碼,請讓我知道,我會編輯並添加它。

謝謝。

如何將我的圖像保存到鏈接保存在 promo_link 在我的數據庫表?

<?php 

include_once('include/connection.php'); 
include_once('include/article.php'); 

$article = new article; 


**if(isset($_GET['id'])) { 
    $id = $_GET['id']; 
$data = $article->fetch_data($id);** 

$articles = $article->fetch_all(); 

?> 

<html> 

<head> 
<title>xclo mobi</title> 
<link rel="stylesheet" href="other.css" /> 
</head> 

<body> 
<?php include_once('header.php'); ?> 


<div class="container"> 
<a href="index.php" id="logo">Category = ???</a> 


    <?php foreach ($articles as $article) { 
    if ($article['promo_cat'] === $_GET['id']) { ?> 


<div class="border"> 
<a href="single.php?id=<?php echo $article['promo_title']; ?>" style="text-decoration: none"> 
<img src="<?php echo $article['promo_image']; ?>" border="0" class="img" align="left"><br /> 


**<a href="<?php echo $data['promo_link']; ?>" target="_blank"><img alt="" title="" src="GO.png" height="50" width="50" align="right" /></a>** 
<br /><br /><br /><br /> 
      <font class="title"><em><center><?php echo $article['promo_title']; ?></center></em></font> 

<br /><br /> 

<font class="content"><em><center><?php echo $article['promo_content']; ?></center></em></font> 

</div><br/><br /> 

      </a> 

<?php } } } ?> 

</div> 
<?php include_once('footer.php'); ?> 
</body> 

</html> 

回答

0

href屬性是空的,因爲你使用的鏈接點擊target="_blank"將在不同的標籤頁中打開同一個頁面。

$data['promo_link']爲空。我不知道爲什麼,因爲沒有代碼。

編輯

看來你忘了括號

$article = new article();

$article->fetch_data($id)很可能返回一個空值替換$article = new article;

正如我所見,您的ID值是「免費」。請確保article->fetch_data("FREE")返回您期望它返回的內容。

我也建議改變你的代碼風格。 這是更容易閱讀:

if ($param){ 
    echo '<div>' . $data["bla"] . '</div>'; 
} 

混合PHP代碼和YOUT HTML代碼,使得它難以閱讀和理解。

注意:<font class="title"><em><center><?php echo $article['promo_title']; ?></center></em></font>已棄用。使用CSS:

HTML/PHP代碼:

echo '<div class="title">' . $article['promo_title'] . '</div>'; 

而CSS:

.title{ 
    text-align: center; 
    font-size: 1.5em; 
} 
+0

這是我對於只有代碼。這是[鏈接]上的下載鏈接相同的代碼(http://www.xclo.co.uk/mobile/appdonate/article.php?id=1) – kevstarlive

+0

那麼我怎麼可以將我的圖像href我的圖像數據庫字段? – kevstarlive

+0

找到您要賦予$ data ['promo_link']參數值的位置。看看那裏出了什麼問題。 –