0

在下面的代码中,我想在一行中加入或内爆所有 $trackersurl 数组。我在不同的行中得到结果,所以我想加入一行。谁能帮我吗?

我正在stackoverflow中搜索结果,但无法遵循。

我的代码在下面:

$sql = "SELECT * FROM announce WHERE torrent = $id ORDER BY seeders DESC";
$query = @mysql_query($sql);
while ($result  = @mysql_fetch_array($query)) {

$trackersurl1 = $result['url'];
$trackersurl2 = "&tr=".$trackersurl1;
$trackersurl = array($trackersurl2);

}

html页面中[var.trackersurl]的结果如下:

&tr=http:ajgdsjhg/ann
&tr=udp://iuysidfu/ann
&tr=udp:wutefghgw/ann
&tr=http://sdhgsjdhgj/ann

我想在下面的一行中加入他们

&tr=http:ajgdsjhg/ann&tr=udp://iuysidfu/ann&tr=udp:wutefghgw/ann&tr=http://sdhgsjdhgj/ann
4

2 回答 2

0

你应该小心sql注入。

您是否要创建一个包含所有跟踪器字符串的数组 ['trackers'] 以用于磁力链接?

<?php
$sql = "SELECT * FROM announce WHERE torrent = ".mysql_real_escape_string($id)." ORDER BY seeders DESC";
$query = mysql_query($sql);

$tracker = null;
if(mysql_num_rows($query)>=1){
    while ($result  = mysql_fetch_array($query)) {
        $tracker .= "&tr=".$result['url'];
    }
}
$tracker = array('trackers'=>$tracker);

//$tracker['trackers'] = "&tr=a.com&tr=b.com&tr=c.com";
?>
于 2013-02-07T07:52:00.767 回答
0

试试这个代码

$newArray=array();
while ($result  = @mysql_fetch_array($query)) {
    $trackersurl1 = $result['title'];
    $newArray[] = "&tr=".$trackersurl1;
}
$urlString=implode('',$newArray);
于 2013-02-07T07:57:29.613 回答