Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pretty simple: Your PHP code is executed <strong>ONCE</strong> when you access the site.</p> <p>So for example the result of this block</p> <pre><code>while($row = mysql_fetch_assoc($result)){ echo "&lt;li onclick=\"toggle('hidden','hidden2','hidden3');\"&gt;".$row['name'].'&lt;li&gt;'; $query2 = "SELECT * FROM site WHERE eid = '".$row['id']."'"; //$query2 = "SELECT * FROM site WHERE eid = ".$row['id']; //$result2 = mysql_query($query2) or die("query2 result error".mysql_error()); $result2 = mysql_query($query2) or die("query2 result error".mysql_error()); } </code></pre> <p>is that <code>$result2</code> holds all the sites of the last company in your list. This is then used in the next loop to generate the corresponding list of sites. Look at the source of the generated HTML file. </p> <p>PHP is a server side language, the code is executed at the server and it is not re-executed by your Javascript functions (i.e. not executed in the browser).</p> <p>What you are after is dynamically loading the data from your server with <a href="http://en.wikipedia.org/wiki/Ajax_(programming)" rel="nofollow noreferrer">AJAX</a> and pass into the generated HTML.</p> <p><strong>Edit:</strong></p> <p>You could also do it without Ajax: Rewrite your PHP like this:</p> <pre><code>$sitequeries = array() while($row = mysql_fetch_assoc($result)){ echo "&lt;li onclick=\"showSites('sites_$row['id']');\"&gt;".$row['name'].'&lt;li&gt;'; $query = "SELECT * FROM site WHERE eid = '".$row['id']."'"; $sitequeries[$row['id']] = mysql_query($query2 or die("query2 result error".mysql_error()); } </code></pre> <p>and</p> <pre><code>&lt;?php foreach($sitequeries as $id =&gt; $query) { echo "&lt;ul class='sites' id='sites_$id'&gt;"; while($row2 = mysql_fetch_assoc($query)){ //... } echo "&lt;/ul&gt;"; } ?&gt; </code></pre> <p>This is not a working example but should give you the right idea. You have to adjust your JS accordingly to show only the corresponding lists, e.g.:</p> <pre><code>function showSites(id) { // Hide all lists with class 'site' here and only display the list with id 'id' e.g. 'sites_5' } </code></pre> <p>But note that this is not a good solution if you have a lot of companies, site, employes, etc. as the generation of the HTML may take a while. Then Ajax is a better choice. </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.
    3. 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