2013-04-06 62 views
-2

對不起,我的英語..從MySQL獲得的陣列數據

在MySQL

具有行名稱iurl ..有數據:1365269423.jpg,1365270586.jpg,1365270666.jpg,1365270683.jpg

我得到它爲:

<?php $s=mysql_query("select iurl from points where id='".$_GET['id']."' "); 

if($s){ 

$array = array(); 

while($t=mysql_fetch_array($s)) { 
$array[] = $t['iurl']; 

    } 

print_r($array); 
?> 

它給我的結果是:Array ([0] => 1365269423.jpg,1365270586.jpg,1365270666.jpg,1365270683.jpg)

而且我真的需要得到它和打印像一個鏈接

我該怎麼辦?

謝謝..

+0

使用'HTML'鏈接。 – Kermit 2013-04-06 18:33:58

回答

1

您可以使用explode();字符串分割成一個數組,然後遍歷打印每個項目:

$images = explode(",", $t["iurl"]); 
foreach ($images as $image) { 
    echo "<a href=\"{$image}\">{$image}</a>"; 
} 
+0

非常感謝你的主意! – brio 2013-04-06 18:56:11

+0

它已經是一個數組,他從數據庫中獲取數據。 – Grmn 2013-04-06 19:16:48

0

我想你問到有結果,或在您的情況一個.jpg文件是你的鏈接的href?如果這樣做:

<a href="<?php echo $t['ur1']?>">......</a> 
0

你從數據庫中獲取,你已經想通了,其結果是一個數組 你需要做的唯一事情是環槽的陣列。

PS:可以考慮使用mysqli的詳細信息在php.net http://www.php.net/manual/en/book.mysqli.php

<?php 
$s=mysql_query("select iurl from points where id='".$_GET['id']."' "); 
while ($row = mysql_fetch_object($s)) { 
    echo '<a href="'.$row->iurl.'" border="0" title=""><img="http://yourhost.com/images/'.$row->image.' alt=""/></a>'; 
} 
?>