php打印href

时间:2017-01-12 09:50:12

标签: php mysql

如何打印一个变量的所有值,从一个href中的mysql数据库中读取它 在下面的代码中,变量是 $ src ,值从数据库中读取,如下所示

$file_query=mysqli_query($conn,"select * from tbl_taskimage where db_taskid='$id'")or die(mysqli_error($conn));
if(mysqli_num_rows($file_query)>0){
    while($r=mysqli_fetch_array($file_query)){
    $src=$r['db_image'];}
    echo"<a href='download.php?src=$src'><img src='../img/download.png'></a>";
}

当我把鼠标放在它上面时,我希望href中的结果是这样的

...... /的download.php?SRC = xxx.png-yyy.jpg-rrr.jpeg

是可能的,怎么做?!!

4 个答案:

答案 0 :(得分:1)

我认为你正在寻找内爆:

<code>
$file_query=mysqli_query($conn,"select * from tbl_taskimage where db_taskid='$id'")or die(mysqli_error($conn));
$src = array();
if(mysqli_num_rows($file_query)>0){
    while($r=mysqli_fetch_array($file_query)){
    $src[]=$r['db_image'];}
}
echo '<a href="download.php?src='.implode('-',$src).'><img src="../img/download.png"></a>';
</code>

答案 1 :(得分:0)

您必须连接变量

echo "<a href='download.php?src=".$src."'><img src='../img/download.png'></a>";

答案 2 :(得分:0)

$file_query=mysqli_query($conn,"select * from tbl_taskimage where db_taskid='$id'")or die(mysqli_error($conn));
if(mysqli_num_rows($file_query)>0){
    while($r=mysqli_fetch_array($file_query)){
    $src=$r['db_image'];}
    echo "<a href='download.php?src=".$src."'><img src='../img/download.png'></a>";

答案 3 :(得分:0)

也许这样的事情会有所帮助:

$src='';
if(mysqli_num_rows($file_query)>0){
while($r=mysqli_fetch_array($file_query)){
    if(empty($src)){
         $src=$r['db_image'];
    } else {
         $src.= '-'.$r['db_image'];
    }
}
echo"<a href='download.php?src=$src'><img src='../img/download.png'></a>";