Note that there are some explanatory texts on larger screens.

plurals
  1. POlist onclick event problem in php
    primarykey
    data
    text
    <p>I'm trying to display the new dynamic list by clicking dynamic list. Why do i call them dynamic list? Because the data is from database. </p> <p>My <strong>idea</strong> is generating a list of companies, when i click one company, a list of all sites in the company is displayed; And then when i click the one site of one company, a list of all employees in the site is displayed.</p> <p>Now i have met a problem. When i click any item in list of companies, a list of sites in the last item of company list shows. And when i click any item in the list of sites, a list of employees of last item in sites is showed.</p> <p>Do you know why? </p> <p>Here is the code and result image:</p> <pre><code>&lt;script language="JavaScript"&gt; function toggle(id,id2,id3) { var state = document.getElementById(id).style.display; if (state == 'block') { document.getElementById(id).style.display = 'none'; if (id2 != undefined)document.getElementById(id2).style.display = 'none'; if (id3 != undefined)document.getElementById(id3).style.display = 'none'; } else { document.getElementById(id).style.display = 'block'; } } &lt;/script&gt; &lt;style type="text/css"&gt; #main{ position:relative; top:20px; left:20px; width:200px; background: lightblue; } #hidden { position:relative; top:5px; left:280px; width:200px; background: lightgrey; display: none; } #hidden2 { position:relative; top:-12px; left:580px; width:200px; background: lightgreen; display: none; } #hidden3 { position:relative; top:100px; left:20px; width:200px; background: lightpink; display: none; } &lt;/style&gt; &lt;?php error_reporting(E_ALL ^ E_NOTICE); include("./conn/connect.php"); $query = "SELECT * FROM entreprise ORDER BY id"; $result = mysql_query($query) or die("result failed: ".mysql_error()); ?&gt; &lt;div id="main" &gt; &lt;?php echo "&lt;ul&gt;"; 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()); } echo "&lt;/ul&gt;"; ?&gt; &lt;/div&gt; &lt;div id="hidden" &gt; &lt;?php echo "&lt;ul&gt;"; while($row2 = mysql_fetch_assoc($result2)){ echo "&lt;li onclick=\"toggle('hidden2','hidden3')\"&gt;".$row2['name'].'&lt; &gt;'; $query3 = "SELECT * FROM salarie WHERE siteid =".$row2['id']; //echo $query3; $result3 = mysql_query($query3) or die("query3 result error".mysql_error()); } echo "&lt;/ul&gt;"; ?&gt; &lt;/div&gt; &lt;div id="hidden2" &gt; &lt;?php echo "&lt;ul&gt;"; while($row3 = mysql_fetch_assoc($result3)){ echo "&lt;li onclick=\"toggle('hidden3')\"&gt;".$row3['prenom'].'&lt; &gt;'; $query4 = "SELECT * FROM salarie WHERE id =".$row3['id']; $result4 = mysql_query($query4) or die("query4 result error".mysql_error()); } echo "&lt;/ul&gt;"; ?&gt; &lt;/div&gt; &lt;div id="hidden3"&gt; &lt;?php echo "&lt;table&gt;"; while($row4 = mysql_fetch_assoc($result4)){ echo "&lt;tr&gt;&lt;td&gt;".$row4['prenom'].'&lt;/td&gt;'; echo "&lt;td&gt;".$row4['nom'].'&lt;/td&gt;&lt;/tr&gt;'; } echo "&lt;/table&gt;"; ?&gt; &lt;/div&gt; </code></pre> <p>Result image: </p> <p><img src="https://hiphotos.baidu.com/%D5%E6%CE%D2%CE%DE%CE%B7/pic/item/2d644b8f8f5e5eca503d922f.jpg" alt="alt text"></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. 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