php 显示有关数据库项目的更多信息

gjmwrych  于 2022-12-02  发布在  PHP
关注(0)|答案(1)|浏览(163)

我需要一个PHP页面的帮助,这个页面显示了一个mysql数据库中关于城市广场周围建筑物的信息。我希望它设置成一开始只显示地址。然后当有人点击某个地址时,它会显示更多关于那个特定建筑物的信息。
我是PHP新手,有两个解决方案我知道会工作,但我不想走这条路,除非我必须。
"这两个解决方案是"
1.为每个建筑物创建一个页面,并将每个地址链接到特定页面,
1.将每个数据库项插入到页面中(而不是使用PHP循环),并隐藏可以为每个地址切换的div。
我现在拥有的代码(它能工作)用于显示地址:

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

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

qjp7pelc

qjp7pelc1#

我找到了解决困境的办法. . . . . .
我使用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代码的底部放置:
$唯一ID ;$请工作;
这样我就可以在link和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
抱歉,如果这是混乱的。谢谢你所有的帮助!

相关问题