Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to use AJAX on top of PHP, as the javascript will process the client side, and the PHP will process the server side. I would suggest using <a href="http://jquery.com" rel="nofollow">jQuery</a> for your <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">AJAX</a> calls.</p> <h3>Your workflow would look like this if you were to use PHP and jQuery:</h3> <ol> <li>User types ID in a <code>&lt;input&gt;</code> box in the HTML page</li> <li>User clicks some sort of button, to run the jQuery AJAX function</li> <li>AJAX function takes the ID in the box through <code>$("input").val()</code>, <code>POSTS</code> it to the PHP page</li> <li><p>PHP processes the ID, matches it in the database (or XML file), and <code>json_encode()</code>'s the resulting rows, to look something like this:</p> <p><code>{ "ID": [ { "name": "Banana", "price": "5" } ] }</code></p></li> <li><p>Your PHP code <code>echo()</code>'s the <code>JSON</code> string</p></li> <li><code>onSuccess()</code>, your jQuery parses the JSON through <code>paseJSON()</code></li> <li>You can then access your <code>name</code> and <code>price</code> through something like <code>data["ID"][0]</code> and <code>data["ID")[1]</code></li> <li>Set the <code>.val()</code> of the other <code>&lt;input&gt;</code> elements to that of <code>data["ID"][0]</code> and <code>data["ID"][1]</code></li> </ol> <h3>Pure PHP:</h3> <ol> <li>Output HTML via PHP that includes the same form elements as above</li> <li>When you press submit, <code>POST</code> the values of the <code>ID</code> element to that same PHP file</li> <li>Have your PHP file recognize that the ID is being <code>POST</code>ed to it</li> <li>Match the ID with the ID in your XML file, and retrieve the corresponding rows</li> <li>Set the text of the other <code>input</code> elements to that of the variables retrieved from step 4</li> </ol> <p>Using pure PHP might be a pain, however, if you're going to eventually add the variables, as you'll need a way to retain the previous variables. If you use AJAX, you simply <code>append()</code> the new items to the same HTML page, then create a separate function to add the prices.</p> <p>You could also potentially find a solution without using PHP, and having a javascript library parse the XML file for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload