0

我需要一个 php 页面的帮助,该页面显示来自 mysql 数据库的有关城镇广场周围建筑物的信息。我希望它设置为首先显示地址。然后,当有人点击某个地址时,它会向他们显示有关该特定建筑物的更多信息。

我是 PHP 新手。我知道有两种解决方案会起作用,但除非我必须这样做,否则我不想走那条路。

这两个解决方案是

  1. 为每个建筑物创建一个页面,并将每个地址链接到特定页面,

  2. 将每个数据库项插入页面(而不是使用 PHP 循环)和隐藏的 div,可以为每个地址切换。


我现在拥有的代码(并且有效)用于显示地址:

   echo "<p><a href="WhatDoIPut???"><h3>   " . stripslashes($rowBuildings[building_address]) . "</h3></a><br>\n";

但是,如果(且仅当)他们单击建筑物地址时,我如何显示其余的建筑物信息?对不起,如果这是一个广泛的话题。我已经阅读了几个论坛,但没有运气。我的问题是没有从数据库中获取信息。

4

1 回答 1

0

我找到了解决我的困境的方法。. .

我正在使用 Javascript 来切换 div(这很简单)。我的问题是切换每个单独的 div,因为它们是由 PHP 脚本添加的(根据数据库条目的数量)。我不知道如何为链接和 div 增加 div id 名称。例子:

 <!--This was the link to toggle the div --> 
 <a href="#" onclick="toggleMe('divid');"><h3>Address</h3></a>

 <!--This was the div to toggle --> 
 <div id="divid">Hello</div>

我的 PHP 插入了多个 div 和链接,所以当你点击一个地址时,所有名为“divid”的 div 都会出现。为了解决这个问题,我向每个 div id 添加了一个 PHP 变量,例如:

$uniqueID = 0;
$PleaseWork = 0;

然后我放在php代码的底部:

$uniqueId++; $请工作++;

这使我可以将变量放在链接和 div id 中,这将一致地计算在一起。总的来说,这里是代码:

Java 切换

> <script type="text/javascript">
> 
>       function toggleMe(a){ var e=document.getElementById(a); if(!e)return
> true; if(e.style.display=="none"){ e.style.display="block" } else{
> e.style.display="none" } return true } </script>

PHP 代码 - 链接和可见项目

<div class="building" align="left" style="margin-left:100px;">
    <? 
    {
 $uniqueID = 0;
 $PleaseWork = &$uniqueID;
 }
 $selectAddress ="SELECT * FROM `buildings` order by building_address";
 $resultAddress = mysql_query($selectAddress);
  while($rowBuildings = mysql_fetch_array($resultAddress)){;
echo "<p><a id=\"displayText\" href=\"#\" onclick=toggleMe(\"divn$PleaseWork\");><h3>   " . stripslashes($rowBuildings[building_address]) . "</a></h3><br>\n";
   echo "<b>For Sale or Rent:</b> " . $rowBuildings[building_saleorrent] . "";
    if(!empty($rowBuildings[building_permonth]))
      echo "<b>Rent Per Month: </b>" . $rowBuildings[building_permonth] . "";
      if(!empty($rowBuildings[building_saleprice]))
      echo "<b>Sale Price: </b>" . $rowBuildings[building_saleprice] . "";
   echo "<br>\n";

PHP 代码 - 隐藏的 DIV

   echo "<div id=\"divn$uniqueID\" style=\"display:none\"><b>Is the Property Listed with a Realtor? </b> " . $rowBuildings[building_realtor] . "<br>\n";
        if(!empty($rowBuildings[building_target]))
        echo "<b>Best Suited for Building: </b>" . $rowBuildings[building_target] . "<br>\n";
    echo "<b>Owner: </b>" . $rowBuildings[building_owner] . "";
    if(!empty($rowBuildings[building_ownphone]))
      echo "<b>  Phone: </b>" . formatPhone($rowBuildings[building_ownphone]) . "";
      if(!empty($rowBuildings[building_ownemail]))
      echo "<b>  Email: </b>" . $rowBuildings[building_ownemail] . "";
    echo "<br>\n";
     echo "<b> Is the building occupied? </b>" . $rowBuildings[building_isoccupant] . "<br>\n";
    if(!empty($rowBuildings[building_occupant]))
      echo "<b>Current Occupant:</b>" . $rowBuildings[building_occupant] . "<br>\n";
    if(!empty($rowBuildings[building_occupantphone]))
      echo "<b>Occupant Phone:</b>" . formatPhone($rowBuildings[building_occupantphone]) . "<br>\n";
        echo "<b>Utilities: </b>" . $rowBuildings[building_utilities] . "<br>\n";
        echo "<b>Stories: </b>" . $rowBuildings[building_stories] . "<br>\n";
        echo "<b>Total Sq. Footage: </b>" . $rowBuildings[building_square] . "<br>\n";
        echo "<b>Footage Breakdown:</b><br> ";
    if(!empty($rowBuildings[building_residential]))
      echo "<b>Residental: </b>" . $rowBuildings[building_residential] . " ";
      if(!empty($rowBuildings[building_lightindustry]))
      echo "<b>Light Industrial: </b>" . $rowBuildings[building_lightindustry] . " ";
      if(!empty($rowBuildings[building_commercial]))
      echo "<b>Residental: </b>" . $rowBuildings[building_commercial] . " ";
      echo "<br>\n";
        echo "<b>Storage: </b>" . $rowBuildings[building_storage] . "&nbsp; <b>Storage Sq. Footage:&nbsp; </b>" . $rowBuildings[building_storefoot] . "<br>\n";
        echo "<b>Inside of Building: </b>" . $rowBuildings[building_inside] . "<br>\n";
        echo "<b>Outside of Building: </b>" . $rowBuildings[building_outside] . "<br>\n";
        echo "<b>Parking: </b>" . $rowBuildings[building_parking] . "<br>\n";
         if(!empty($rowBuildings[building_issues]))
      echo "<b>Issues With the Building: </b>" . $rowBuildings[building_issues] . "<br>\n";
       if(!empty($rowBuildings[building_features]))
      echo "<b>Main Features of the Building: </b>" . $rowBuildings[building_features] . "<br>\n";
       if(!empty($rowBuildings[building_notes]))
      echo "<b>Notes on the Building: </b>" . $rowBuildings[building_notes] . "<br>\n";     
    echo "</div></p>";
$uniqueId++;
$PleaseWork++;
}


?>

我使用各种网站来收集这些信息。这里有一些:

http://www.dynamicdrive.com/forums/showthread.php?41829-Toggle-Div-in-PHP

http://php.net/manual/en/language.references.unset.php

对不起,如果这令人困惑。感谢你的帮助!

于 2012-08-23T15:15:26.627 回答