我正在试图找出如何删除逗号,比如说 [' address_2']字段,如果这是空的,如果没有输入,也不会显示[' tel']电话号码的图标,这似乎很难在回声中工作。
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)) {
echo "<div class='result-container'>
<div class='result-wrap'>
<div class='leftbox'>
<div class='titlebox'>
<h2>" . $row['company_name'] . "</h2>
<p><strong>" . $row['company_services'] . "</strong></p>
</div>
<div class='box'><strong> Address: </strong>" . $row['address_1'] . ", " . $row['address_2'] . ", " . $row['town'] . ", " . $row['county'] . ", " . $row['postcode'] . "</div>
<div class='box'><strong> Telephone: </strong>" . $row['tel'] ."<strong> Mobile: </strong>". $row['mob'] . "</div>
<div class='iconbox'>
<a href='" . $row['tel'] . "'><img src='img/icons/phone.png' class='hvr-push'></a>
<a href='" . $row['mob'] . "'><img src='img/icons/mobile.png' class='hvr-push'></a>
<a href='mailto:" . $row['email'] . "'><img src='img/icons/email.png' class='hvr-push'></a>
<a href='" . $row['web_url'] . "'><img src='img/icons/web.png' class='hvr-push'></a>
</div>
<div class='buttonwrap'><div class='buttonbox'><p>View Profile</p></div></div>
</div>
<div class='rightbox'>
<div class='service-pic'>
<img src='img/image1.png'>
</div>
<div class='mapbox'>
" . $row['gmap_url'] . "
</div>
</div>
</div>
<br/>";
}
}
答案 0 :(得分:0)
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)) {
?>
<div class='result-container'>
<div class='result-wrap'>
<div class='leftbox'>
<div class='titlebox'>
<h2><?=$row['company_name']?></h2>
<p><strong><?=$row['company_services']?></strong></p>
</div>
<div class='box'><strong> Address: </strong><?=$row['address_1']?>,
<?php
if(!empty($row['address_2'])){
?>
  <?=$row['address_2']?>,
<?php
}
?>
  <?=$row['town']?>,  <?=$row['county']?>,  <?=$row['post code']?></div>
<div class='box'><strong> Telephone: </strong><?=$row['tel']?><strong> Mobile: </strong><?=$row['mob']?></div><div class='iconbox'>
<a href='
<?=$row['tel']?>'><img src='img/icons/phone.png' class='hvr-push'></a>
<a href='
<?=$row['mob']?>'><img src='img/icons/mobile.png' class='hvr-push'></a>
<a href='mailto:"
<?=$row['email']?>'><img src='img/icons/email.png' class='hvr-push'></a>
<a href='"
<?=$row['web_url']?>'><img src='img/icons/web.png' class='hvr-push'></a>
</div>
<div class='buttonwrap'><div class='buttonbox'><p>View Profile</p></div></div>
</div>
<div class='rightbox'>
<div class='service-pic'>
<img src='img/image1.png'>
</div>
<div class='mapbox'>
<?=$row['map_url']?>
</div>
</div>
您可以使用Mysql,请在此处查看:http://php.net/manual/es/book.mysqli.php 最后一个提示:'不要将HTML输入回声'