1

我将如何重写此代码以仅<h3>在查询返回结果时才显示标签?

我对 PHP 很陌生,我知道这可以做到,我只是不确定最好的方法。

我能得到的任何帮助都会很棒。

先感谢您。

我当前的代码如下。

<h3 class="state" name="art">Art</h3>
<?php
    if (mysql_error() > "") print mysql_error() . "<br>";
    mysql_select_db($database_name, $db);
    if (mysql_error() > "") print mysql_error() . "<br>";
      $query = mysql_query("SELECT * FROM member_page WHERE community_id = $cityid AND category=1 ORDER BY entity_name");

        echo "";
      while ($row = mysql_fetch_array($query))

      {
          echo "<div id='result'><div id='entity_name'><h4>".$row['entity_name']."</h4></div><img width='275' height='170' src='images/".$row['id']."/coverphoto/".$row['cp_path']."' ><div id='searchblurb'><p>".$row['search_blurb']."</p></div><a border='0' href='member-info.php?id=".$row['id']."' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage('go','','images/custom/go-over.png',1)'><img src='images/custom/go-out.png' alt='Visit this community' width='120' height='40' id='go' border='none'></a> 
        </div>";
      }
      echo "";
?>
4

1 回答 1

1

You can try some thing like this:

if(mysql_num_rows($query) != 0)
{
    echo "<h3 class='state' name='art'>Art</h3>";
}

Please also take note that mysql_* functions are depreciated try to learn PDO HERE


UPDATE

Im not sure if this is what you wanted but you can try this:

if(mysql_num_rows($query) != 0)
{
    echo "<h3 class='state' name='art'>Art</h3>";
    while($row = mysql_fetch_array($query))
    {
        echo "<div id='result'><div id='entity_name'><h4>".$row['entity_name']."</h4></div><img width='275' height='170' src='images/".$row['id']."/coverphoto/".$row['cp_path']."' ><div id='searchblurb'><p>".$row['search_blurb']."</p></div><a border='0' href='member-info.php?id=".$row['id']."' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage('go','','images/custom/go-over.png',1)'><img src='images/custom/go-out.png' alt='Visit this community' width='120' height='40' id='go' border='none'></a> 
    </div>";
  }
}
于 2013-06-08T00:16:20.530 回答