我需要一个php页面的帮助,该页面显示来自mysql数据库的有关城镇广场周围建筑物的信息。我想要它设置,以便地址是最初显示的唯一东西。然后当有人点击某个地址时,会向他们显示有关该特定建筑物的更多信息。
我是PHP的新手。我知道有两种解决方案可行,但除非必须,否则我不想走那条路。
这两个解决方案
为每个建筑创建一个页面,并将每个地址链接到特定页面和
将每个数据库项插入页面(而不是PHP循环)和隐藏的div,可以为每个地址切换。
我现在拥有的代码(并且可以使用)用于显示地址:
echo "<p><a href="WhatDoIPut???"><h3> " . stripslashes($rowBuildings[building_address]) . "</h3></a><br>\n";
但是,如果(并且仅当)他们点击建筑物地址,我该如何显示建筑物信息的其余部分?对不起,如果这是一个广泛的话题。我读过几个论坛,但没有运气。我的问题是没有从数据库中获取信息。
答案 0 :(得分: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 ++; $ PleaseWork ++;
这允许我将变量放在链接中,并将div id一致地计算在一起。总而言之,以下是代码:
Java to toggle
> <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代码 - 链接&amp;可见项目
<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] . " <b>Storage Sq. Footage: </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
很抱歉,如果这令人困惑。谢谢你的帮助!