我有一个插页:
$sql="INSERT into tasks(TITLE,DESCRIPTION) VALUES('$projectName',
'Description Documents: [url=http://myurl/$documentID/]$documentName[/url]')";
我之前有一个查询:
$result1 = mysqli_query($con,"SELECT ID, NAME, IBLOCK_ID FROM b_iblock_element WHERE IBLOCK_ID = '36' ORDER BY ID DESC LIMIT 6");
while($row = mysqli_fetch_array($result1))
{
$documentID = $row['ID'];
$documentName = $row['NAME'];
}
这会返回6个ID。现在我希望这些ID中的每一个在INSERT中形成一个URL。所以基本上描述将返回6个链接,每个链接链接到相关的ID。
这可能吗?如果是这样的话?
答案 0 :(得分:1)
只需构建一个包含所有Url的字符串,方法是将它们连接到例如implode(),然后将此脚本添加到您的描述中。
您还可能需要将NAME字段添加到您的选择查询中,以便能够从数据库中获取它。
$result1 = mysqli_query($con,"SELECT ID, IBLOCK_ID FROM b_iblock_element WHERE IBLOCK_ID = '36' ORDER BY ID DESC LIMIT 6");
while($row = mysqli_fetch_array($result1))
{
$documentID = $row['ID'];
$urls[] = "[url=http://myurl/$documentID/]" . $row["NAME"] . "[/url]";
}
$allUrls = implode(' ', $urls);
$sql="INSERT into tasks(TITLE,DESCRIPTION) VALUES('$projectName',
'Description Documents: " . $allUrls ."')";