<div dir="ltr">Andrew, my advice is quite simple, stick to CSS and simple HTML,<div><br></div><div>then when you have something which looks OK, and works, think about Javascript</div><div><br></div><div>You really dont need php for most things, so start at the beginning, and work your way up.</div><div><br></div><div>To do php, set up a webserver on your local machine, and start simple, then add little by little as you learn.</div><div><br></div><div>Mark</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 22 May 2020 at 19:48, Jeremy Nicoll <<a href="mailto:jn.ml.elx.813@letterboxes.org">jn.ml.elx.813@letterboxes.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 22 May 2020, at 18:52, Andrew Ramage wrote:<br>
<br>
> I have my website up and (mostly) correct.  I just need to get the <br>
> Directory to function correctly.<br>
> <br>
> <a href="http://andrewnramage.co.uk" rel="noreferrer" target="_blank">andrewnramage.co.uk</a><br>
> <br>
> Copying and altering code  from w3schools, I have this function. Why <br>
> will it not work?<br>
<br>
You're not showing us all the code.<br>
<br>
None of us can see the php file(s) because if we try to look at <br>
<br>
<a href="http://andrewnramage.co.uk" rel="noreferrer" target="_blank">http://andrewnramage.co.uk</a>\xyz.php<br>
<br>
what we'd see is the result of executing that php code, not its<br>
actual source.<br>
<br>
When you say something does not work, that's the world's most <br>
useless statement.<br>
<br>
We have no idea what (if anything) does execute both in your browser <br>
and on the server.<br>
<br>
You could use your browser's developer tools to watch your javascript<br>
code execute, and (I expect) somehow log what the php code does on <br>
the server (though I don't know how that's done, especially if the server<br>
in question is not yours).  But I'm sure google will help.<br>
<br>
<br>
<br>
> <script><br>
> //  xhttp.onreadystatechange = function() {<br>
> //    if (this.readyState == 4 && this.status == 200) {<br>
>        myFunction(this);<br>
> //    }<br>
<br>
In that set of lines 3/4 of them are commented out.  I'm not <br>
sure if the myFunction() bit is also not functioning because of<br>
the commented-out bits.<br>
<br>
If it is not being run and is not meant to be run, why did you include it <br>
in the question?<br>
<br>
If it is being run, where is the definition of myFunction()  ?   We are<br>
not clairvoyant.<br>
<br>
WHAT do you think it is mean to do?<br>
<br>
<br>
<br>
>    };<br>
>    xhttp.open("GET", "directory.xml", true);<br>
>    xhttp.send();<br>
> }<br>
<br>
Do those lines execute?   I'm guessing they cause the <br>
directory.xml file to be fetched, but is that right?  Under what <br>
circumstances does it happen?  Before this page loads, or <br>
asynchronously?  If the latter how does any code that then <br>
uses it know it's been fetched?<br>
<br>
<br>
Skipping over the function dirmusic() definition for now <br>
you also have <br>
<br>
> <button  margin-bottom=400px onclick=directory.php>Refresh</button><br>
<br>
I was under the impression that the onlick action of a button would be a<br>
call of a JS function.  But you seem to be referencing a php page on your <br>
server.<br>
<br>
If I'm right (that the action needs to be a JS function call) I can't imagine that <br>
your code will do anything at all.<br>
<br>
If it does somehow execute  directory.php   no-one here has a clue what is <br>
in that file.<br>
<br>
<br>
<br>
> <div id="dir">Directory goes here</div><br>
> <script><br>
>     musicdir();<br>
> </script><br>
<br>
What is   musicdir()    meant to do?<br>
<br>
Where is the function defined?<br>
<br>
<br>
You'll note it is NOT the thing defined here:<br>
<br>
> function dirmusic() {<br>
<br>
<br>
I have to ask... do you have any experience programming anything?<br>
<br>
You're making loads of beginner-type mistakes, not the sort of <br>
thing I'd expect to see an experienced programmer do.  <br>
<br>
Getting a mix of JS executed in a browser and PHP executed on a <br>
server to work, if you don't CLEARLY understand the relationship <br>
between them, and the limitations on what each can do, is going <br>
to be hard work.<br>
<br>
I think you're trying to be too clever.  In your position I would set <br>
up some much simpler pages - some eg just with JS on them, and <br>
learn how to use your browser's dev tools, especially its JS <br>
debugger ... so you can later watch whether your more complex <br>
JS is doing what you expect.<br>
<br>
<br>
I'd also learn how to debug php, with some simple examples on<br>
your server.   See eg:<br>
<br>
 <a href="https://blog.teamtreehouse.com/how-to-debug-in-php" rel="noreferrer" target="_blank">https://blog.teamtreehouse.com/how-to-debug-in-php</a><br>
<br>
or the simpler options described at<br>
<br>
 <a href="https://www.php.net/manual/en/debugger.php" rel="noreferrer" target="_blank">https://www.php.net/manual/en/debugger.php</a><br>
<br>
where the idea of one is eg that when the php program needs to <br>
show the programmer what the value of something is, it generates<br>
some literal HTML containing the diagnostic message.  So the <br>
programmer sees that inside the generated web page that their <br>
browser fetches.  <br>
<br>
Anothr example creates log file (which will of course be on the <br>
server) and writes logging info to that.  Whether you can do that <br>
in your case might depend on what ther webhosting company <br>
let you do (unless it's your own server, of course).<br>
<br>
Ignore the suggesions to use various sophisticated php debuggers;<br>
they're fine for professional programmers who're going to be doing<br>
this every day... but they'll take ages to learn how to use.  Stick to <br>
simple methods where you can understand how they work.<br>
<br>
<br>
I would not try to make the two sides (JS in a browser and php on a<br>
server) co-operate until I knew how to do adequate debugging of<br>
both parts..<br>
<br>
<br>
It looks to me as if the intention of the code in the function is to <br>
read the xml file  - which seems to contain a list of song elements<br>
inside a directory one... and is presumably generated elsewhere<br>
and instead make the thing that generates the XML data generate<br>
an html table in eg "mytable.htm"<br>
<br>
Then the current page could be a .shtml one rather than .html and <br>
you could embed the current copy of the most-recently generated<br>
table with eg <br>
<br>
 #include virtual="/path/to/mytable.htm"<br>
<br>
There are disadvantages to using shtml and server-side includes, <br>
mainly that unless you run a server on your own PC you can't test <br>
the result without uploading the shtml files to the wehost's server,<br>
because it's the server that sees the "shtml" extension on a file and <br>
preprocesses it to expand the embedded #include requests.<br>
<br>
 See: <a href="https://en.wikipedia.org/wiki/Server_Side_Includes" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Server_Side_Includes</a><br>
<br>
<br>
Note: I have never used php, nor JS.  But I did program for a <br>
living.<br>
<br>
-- <br>
Jeremy Nicoll - my opinions are my own.<br>
<br>
-- <br>
EdLUG mailing list<br>
<a href="mailto:EdLUG@lists.edlug.org.uk" target="_blank">EdLUG@lists.edlug.org.uk</a><br>
<a href="https://lists.edlug.org.uk/mailman/listinfo/edlug" rel="noreferrer" target="_blank">https://lists.edlug.org.uk/mailman/listinfo/edlug</a></blockquote></div>