1

Hi i have a repeating recordset, in which i want to hide some entry(html div) in a row as required. my database has a table with 7 columns, now i have a condition when i dont wont to display a entry(element) in a row.

to explain further please look at my html code block.

<?php do { ?>
<div class="category-container">
<div class="category-image"><?php echo $list['image']?></div>    
<div class="category-desc"> <a href="<?php echo $list['titlelink']?>"><?php echo $list['title']?></a>
<p><?php echo $list['description']?></p></div>       
<div class="rating<?php echo $list['rating']?>" >Editors' rating: </div>    
<div class="category-download-btn"><a href="<?php echo $list['download']?>">&raquo; Download &raquo;</a></div>    
<div class="category-buy-btn"><a href="<?php echo $list['buy']?>">&laquo; Buy &laquo;</a></div>    
</div> <?php } while ($list = mysql_fetch_assoc($result2)); ?>

i have a div ("class=category-buy-btn") which i want to hide in case when there is no buy link, i have set it fetch url from database.

A simple approach to do this that come to me is making a new column 'buydiv' and putting the entire div in this column 'buydiv' and not to put value in row which i dont want to show, like this.

<?php echo $list['buydiv']?>

in place of

<div class="category-buy-btn"><a href="<?php echo $list['buy']?>">&laquo; Buy &laquo;</a></div>

content of $list['buydiv'] will then have these values.

<div class="category-buy-btn"><a href="<?php echo $list['buy']?>">&laquo; Buy &laquo;</a></div>

Now this is really not a good aproach to do it, can someone please suggest me any better way to do it.

Thanks.

4

1 回答 1

0

只需以$list['buy']非空为条件:

<?php if (!empty($list['buy'])) : ?>
<div class="category-buy-btn"><a href="<?php echo $list['buy']?>">&laquo; Buy &laquo;</a></div>    
<?php endif ?>

更新:为了确保您的 UTF-8 字符串正确显示,您需要告诉浏览器将页面解释为 UTF-8:

header('Content-Type: text/html; charset=UTF-8');

并确保您的 SQL 查询以 UTF-8 运行:

mysql_query("SET NAMES 'utf8'");

有关更多信息,请参阅此内容,有关 PHP 中 Unicode 的更详尽指南,请参阅此内容。这可能是一个令人困惑的话题,因此值得一读。这也是非常有启发性的阅读:

每个软件开发人员绝对、绝对必须了解 Unicode 和字符集的绝对最低要求(没有借口!)

于 2012-06-02T05:28:46.953 回答