【发布时间】:2018-01-18 22:59:57
【问题描述】:
所以,我有一个名为 db.php 的 php 文件来复制某种数据库。这基本上是一个包含一些多维关联数组的文件:
<?php
$arrShowcases = array(
"1"=>array("title"=>"Landing Page", "descr"=>"Welcome!", "img"=>"actions-landing.jpg", "polygon"=>array(
0=> array(
"points"=>"1338,4,1338,50,1272,50,1272,4",
"link"=>"69",
"modalbody"=>"This button lets you Signup on the webapp",
"modaltitle"=>"Signup Button"
),
1=> array(
"points"=>"1246,12,1249,44,1206,44,1204,14",
"link"=>"2",
"modalbody"=>"This button redirects you for the login form",
"modaltitle"=>"Login Button"
)
)),
"2"=>array("title"=>"Login page", "descr"=>"Make your login", "img"=>"actions-login.jpg", "polygon"=>array(
0=> array(
"points"=>"1338,4,1338,50,1272,50,1272,4",
"link"=>"69",
"modalbody"=>"This button lets you Signup on the webapp",
"modaltitle"=>"Signup Button"
),
1=> array(
"points"=>"1246,12,1249,44,1206,44,1204,14",
"link"=>"69",
"modalbody"=>"This button redirects you for your dashboard",
"modaltitle"=>"Login Button"
)
))
);
?>
然后,我有一个带有 section 元素的 html 页面,我需要在其中更改页眉标题、副标题、图像和一些多边形点:
<section>
<div class="container">
<div class="row">
<div class="col-md-3">
<?php include cfgPath."/includes/menu.html"; ?>
</div>
<div class="col-md-9">
<h1 class="page-header"><i class="glyphicon glyphicon-picture"></i> Landing page</h1>
<h3>// Lorem ipsum...</h3>
<div class="col-md-12">
<div style="position:relative;">
<img id="pageScreenshot" src="<?php echo cfgRoot; ?>/assets/images/actions-landing.jpg" class="img-responsive" alt="Landing Page"/>
<svg id="svgImageMap" width="1366" height="768">
<polygon points="1338,4,1338,50,1272,50,1272,4" data-originalpoints="1338,4 1338,50 1272,50 1272,4" data-id="0"/>
<polygon points="1246,12,1249,44,1206,44,1204,14" data-originalpoints="1246,12 1249,44 1206,44 1204,14" data-id="1"/>
<polygon points="378,43,446,42,445,11,377,9" data-originalpoints="378,43 446,42 445,11 377,9" data-id="2"/>
<polygon points="196,10,367,10,366,42,195,43" data-originalpoints="196,10 367,10 366,42 195,43" data-id="3"/>
<polygon points="121,16,120,35,164,39,164,17" data-originalpoints="121,16 120,35 164,39 164,17" data-id="4"/>
<polygon points="14,15,13,40,95,43,95,12" data-originalpoints="14,15 13,40 95,43 95,12" data-id="5">
</svg>
</div>
<!-- data original points: X1,Y1 X2,Y2 X3,Y3 X4,Y4 -->
</br>
<a class="btn btn-success btn-sm btn-block" href="<?php echo cfgRoot; ?>/app/showcase/showcaseView.php">Go Back</a>
</div> <!-- colmd12 -->
</div> <!-- colmd9 -->
</div> <!-- row -->
</div> <!-- container -->
</section> <!-- section -->
正如您在上面的 html 中看到的 section 元素,我手写了所有信息。但是,我的目标是使用 db.php 文件中提供的内容更改该信息。
我想要类似 nameofthepage.php?id=1 的东西(并且数组位置 1 中提供的所有信息都转到 html)或者这个:nameofthepage.php?id=2 (以及在数组的位置 2 转到 html)。有什么建议或提示来获得这种行为?
到目前为止,我尝试过这样的回声:
<?php echo $arrShowcases[positions-that-i-want]["information-that-i-want"]; ?>
更改硬编码的 html,但这并不能获得我需要的动态行为。
【问题讨论】:
-
你试过什么?读起来就像你在要求某人为你做这件事。您需要做的就是使用
$_GET['id']获取?id参数,然后引用数组的适当部分,例如$arrShowcases[1]['title']是第 1 页的标题等... -
AJAX 的典型情况。
-
@iquellis 不是真的,因为它可以在服务器上生成。无需异步调用。
-
@Andy 我没有要求有人为我做这件事,我要求提供建议或提示,并为此表示感谢。我用我尝试过的方法更新了这个问题,但我不知道更多,因为我从未使用过 PHP,也没有使用过 AJAX 或其他任何东西。
标签: php html multidimensional-array associative-array