diff options
| -rw-r--r-- | index.php | 19 | ||||
| -rw-r--r-- | src/main.ts | 7 |
2 files changed, 12 insertions, 14 deletions
@@ -3,19 +3,18 @@ header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Content-Type"); $method = $_SERVER['REQUEST_METHOD']; $xml = simplexml_load_file("./terc.xml"); -// var_dump($xml); if ($method === "GET") { - // $result = $xml->xpath('//row/NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()'); - $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()'); + $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()'); } else if ($method === "POST") { $body = file_get_contents('php://input'); - // echo $body; - // echo '//row/NAZWA[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'; - $result = $xml->xpath('//row/WOJ[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'); -} else { - $result = $xml->xpath('//row/NAZWA[text()="ŁÓDZKIE"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'); - $result = $xml->xpath('//WOJ[text()="10"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'); - $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()'); + $one_xpath = true; + if (!$one_xpath) { + $id = $xml->xpath('//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ'); + $id = "{$id[0]}"; + $result = $xml->xpath('//WOJ[text()=' . $id . ']/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'); + } else { + $result = $xml->xpath('//WOJ[text()=//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()'); + } } $result = array_map(function ($x) { return "$x"; diff --git a/src/main.ts b/src/main.ts index 7ecd320..2406f04 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,11 +5,11 @@ const URL = "http://localhost:8000/index.php"; (async () => { const voivs = await (await fetch(URL)).json() as string[] const tbody = document.getElementById('tds-here') as HTMLTableSectionElement; - for (let i = 0; i < voivs.length; i += 2) { + for (const v of voivs) { const tr = document.createElement("tr") const td = document.createElement("td") - td.innerText = voivs[i + 1] - td.onclick = () => showCities(voivs[i + 1], voivs[i]); + td.innerText = v + td.onclick = () => showCities(v, v); tr.appendChild(td) tbody.appendChild(tr) } @@ -20,7 +20,6 @@ async function showCities(n: string, id: string) { method: "POST", body: id, })).json() as string[] - // console.log(res) const nh = document.getElementById("name-here") as HTMLTableRowElement const vt = document.getElementById("vtds-here") as HTMLTableSectionElement vt.innerHTML = '' |
