0

I created some basic GUI where I read the identification of some items from a XML file via PHP.

So when you click on a item it would go to something like www.example.com/item_id001

Now, I have a menu in this application. But I just don´t seem to figure out what would be the wast way to change the menu links based on the item selected, PHP, javascript. Not sure what is the normal procedure for this.

Basically on the page there are 10 items. Now I have hardcoded the menu to go always to item1. So if you click the button "Information" in the menu, it will go to the page that displays the information of item1.

Now this makes sense if you only have 1 thing listed, but not several. My idea is the user clicks on a item, and an arrow or selection is showed next to the item to indicate the users that ITEM is now active. Now if you would click on the menu "Information" again, it would go to the page (or pass via session) the ID of the user selected item.

I made it sound to complicated but this is the most basic thing in any web interface. What would be the best procedure to go with this? Change the links on the fly with javascript? Or change the PHP session? Can someone point to some very newbie basic examples?

Im not a coder so I just use what I find around. Usually I pay developers for stuff, but this is just to embarrassing as its something just to simple to actually hire someone to explain me how to do this. I found some ideas on the net, but im actually curious on what is the method most webapps use this days.

Thank you

4

1 回答 1

1

我认为您希望在总共 10 个链接中,当前/活动页面的链接应该被区分/突出显示。

你可以做这样的事情。

注意:你需要告诉 PHP 这是哪个页面。在这里,在这段代码中,我通过使用 $_GET 变量来告诉它。您当然可以使用 $_SESSION 或其他任何东西来传递此信息。

SEE UPDATED CODE BELOW
Codepad.viper-7.com 上的演示

更新:

index.php        //intial file, where all car models are shown

specific.php     //the file, where customized menu will be shown,
                 //based on the ID we got from index.php

代码:

index.php(假设这个用户在他的 OWN xml 文件中有Alpha Romeo,模型。T-100

<a href="specific.php?carid=alpha_romeo" />Alpha Romeo</a>
<a href="specific.php?carid=t-100" />T-100</a>

specific.php(用户来自 index.php 链接)

<?php
$carid = $_GET["carid"];
?>
<a href="show.php?info=car_info&carid=<?php echo $car_id; ?>" />Car Info</a>
<a href="show.php?info=p_list&carid=<?php echo $car_id; ?>" />Part Lists</a>
<a href="show.php?info=foo&carid=<?php echo $car_id; ?>" />Foo</a>

show.php

$carid = $_GET["carid"];
$info = $_GET["info"];

//show INFO for CARID

如您所见,在指向 的链接中show.php,动态汽车 ID 被回显/打印。Show.php应该得到 car_id 并进行相应的处理。

于 2012-08-09T02:23:53.773 回答