根据按钮id和值,使用php生成列表

根据按钮id和值,使用php生成列表,php,ajax,Php,Ajax,我是网络开发新手,并不完全了解我需要的一切。因此,我尝试在单击按钮时使用php从xml文件生成一个列表。生成取决于按钮的id和值 以下是生成列表的php: <?php $art_c=$_REQUEST["art"]; $an_c=$_REQUEST["an"]; $fisier="arh.xml"; $xml=simplexml_load_file($fisier) or die("Unable to load XML file!"); foreach($xml->an as $

我是网络开发新手,并不完全了解我需要的一切。因此,我尝试在单击按钮时使用php从xml文件生成一个列表。生成取决于按钮的id和值

以下是生成列表的php:

<?php

$art_c=$_REQUEST["art"];
$an_c=$_REQUEST["an"];
$fisier="arh.xml";
$xml=simplexml_load_file($fisier) or die("Unable to load XML file!");

foreach($xml->an as $an)
{
    if($an['anid']==$an_c)
    {
        foreach($an->nr as $nr)
        {
            if($nr['nrid']==$nr_c)
            {
                foreach($xml->articol as $art)
                {
                    $univ = array();
                    $aut = array('','','','','','','','','','');
                    $articol=trim($art).".xml";
                    $xmlart=simplexml_load_file($articol) or die("Unable to load XML file!");

                    echo '<html> <body><div id="special">Title:&nbsp</div></body></html>';
                    echo "<a href=".trim($art).".php".">";
                    $tit=$xmlart->titlu;
                    echo "$tit</a>";
                    echo "<br/>";
                    echo '<html> <body><div id="special">Autori:&nbsp</div></body></html>';

                    foreach($xmlart->autor as $autor)
                    {
                        $idx=$autor['univ'];
                        for($i=0;$i<sizeof($univ);$i++)
                        {
                            if(strcmp($univ[$i],$idx)==0)break;
                        }
                        if($i>=sizeof($univ))
                        {
                            $univ[$i]=$idx;
                        }
                        if(strlen($aut[$i])==0)$aut[$i]=$autor;
                        else $aut[$i]=$aut[$i].', '.$autor;
                    }

                    for($i=0;$i<sizeof($univ);$i++)
                    {
                        echo $aut[$i].' - '.$univ[$i];
                        echo "<br/>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp";
                    }

                }
            }
        }
    }


}

echo "<br/>";
an作为$an)
{
如果($an['anid']=$an_c)
{
foreach($an->nr为$nr)
{
如果($nr['nrid']=$nr\U c)
{
foreach($xml->articol as$art)
{
$univ=array();
$aut=数组(“”,“”,“”,“”,“”,“”,“”,“”,“”,“”,“”);
$articol=trim($art)。“.xml”;
$xmlart=simplexml_加载文件($articol)或die(“无法加载XML文件!”);
echo“标题:”;
回声“;
回声“
”; echo“自动识别:”; foreach($xmlart->autor作为$autor) { $idx=$autor['univ']; 对于($i=0;$i=sizeof($univ)) { $univ[$i]=$idx; } 如果(strlen($aut[$i])==0)$aut[$i]=$autor; else$aut[$i]=$aut[$i].','.$autor; }
对于($i=0;$i您的ajax请求不正确,您没有设置“art”和“an”的值,它应该类似于“cuprins.php?art=xxx&an=yyy”

您的javascript是什么来进行ajax调用的?函数cuprins(art,an){var xmlhttp=new XMLHttpRequest();xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){document.getElementById(“art”).innerHTML=xmlhttp.responseText;document.getElementById(“an”).innerHTML=xmlhttp.responseText;}xmlhttp.open(“GET”,“cuplins.php?art&an”,true);xmlhttp.send();}
<?xml version="1.0" encoding="UTF-8" ?> 
<rev>
  <an anid="2014">
    <nr nrid="1" data="27 martie">
      <articol>
        <titlu>titlu1</titlu> 
        <autor univ="UAIC">Ionescu</autor> 
        <autor univ="UMF">Cata</autor> 
        <autor univ="UMF">Stan</autor> 
        <autor univ="UAIC">Alex</autor> 
        <autor univ="UAIC">Dan</autor> 
        <tag>tag1,tag2,tag3</tag> 
        <id>2014_1_1</id> 
      </articol>