【发布时间】:2016-01-10 11:19:45
【问题描述】:
我正在尝试从数据库查询中输出项目描述。
这段代码应该输出带有名称等的描述...
<?PHP
$type = "item";
$limit = 16;
$preparedStatement = $SQL->prepare('SELECT * FROM z_shop_offer WHERE offer_type = :type LIMIT :limit');
$preparedStatement->bindParam(':type', $type, PDO::PARAM_STR);
$preparedStatement->bindParam(':limit', $limit, PDO::PARAM_INT);
$preparedStatement->execute();
if ($preparedStatement->rowCount() > 0) {
// Define how we want to fetch the results
$preparedStatement->setFetchMode(PDO::FETCH_ASSOC);
$iterator = new IteratorIterator($preparedStatement);
foreach ($iterator as $item) {
echo '
<div class="ServiceID_Icon_Container" id="ServiceID_Icon_Container_'.$item['id'].'">
<div class="ServiceID_Icon_Container_Background" id="" style="background-image:url('.$layout_name.'/images/serviceid_icon_normal.png);">
<div class="ServiceID_Icon" id="ServiceID_Icon_'.$item['id'].'" style="background-image:url(' . $config['site']['item_images_url'] . $item['itemid1'] . $config['site']['item_images_extension'] . ');" onclick="ChangeService('.$item['id'].', 12);" onmouseover="MouseOverServiceID('.$item['id'].', 12);" onmouseout="MouseOutServiceID('.$item['id'].', 12);">
<div class="PermanentDeactivated">
<span class="HelperDivIndicator" onmouseover="ActivateHelperDiv($(this), \''.$item['offer_name'].'\', \''.htmlentities($item['offer_description']).'<BR><BR>\', \'\');" onmouseout="$(\'#HelperDivContainer\').hide();">
<div class="ServiceID_HelperDiv"></div>
</span>
</div>
</div>
</div>
</div>
';
}
}
?>
我已经尝试过htmlentities、htmlspecialchars 和addslashes。
这是存储在数据库中的描述(在这个上,它停止显示带有描述的工具提示。
激活一小时 1.5 倍以上的经验。它只有一次充电。 在一个处于活动状态时使用任何其他注入只会堆叠它 时间而不是经验。如果您注销或 死。
如何正确转义/输出描述?
【问题讨论】:
-
在foreach里面,添加print_r($item);你看到了什么?
-
添加斜杠应该可以工作
-
Array ( [id] => 6 [points] => 25 [itemid1] => 23474 [count1] => 1 [itemid2] => 0 [count2] => 0 [offer_type] => item [offer_description] => Activate one hour of 1.5x more Experience. It has only one charge. Using any other injection while one is active will only stack it's time and not the experience. The time will not stop if you log out or die. [offer_name] => Experience Injection Tube [category] => 1 [bought] => 0 )这是第五项@Dagon -
@charlietfl
addslashes不适用于第 5 项 -
有些地方不对,因为
it's在添加斜杠后应该看起来像it\'s
标签: javascript php mysql pdo