Jump to content

how to pass the value precisely?


garcon1986

Recommended Posts

Hello,

 

I have a problem dealing with the values in php.  You can see the code following:

    <script language="JavaScript">
        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';
                }
            }
    </script>
    <style type="text/css">
    #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;
    }
    </style>
    	<?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());
    		
    	?>
    <div id="main">
    	<?php
    		echo "<ul>";
    		while($row = mysql_fetch_assoc($result)){
    			echo "<li onclick=\"toggle('hidden','hidden2','hidden3');\">".$row['name'].'<li>';
    			$query2 = "SELECT * FROM site WHERE eid = '".$row['id']."'";
    			//echo $query2;
    			$result2 = mysql_query($query2) or die("query2 result error".mysql_error());
    		}
    		echo "</ul>";
    	?>
    </div>
    <div id="hidden">
    	<?php
    		echo "<ul>";
    		while($row2 = mysql_fetch_assoc($result2)){
    			echo "<li onclick=\"toggle('hidden2','hidden3')\">".$row2['name'].'</li>';
    			$query3 = "SELECT * FROM salarie WHERE siteid =".$row2['id'];
    			//echo $query3;
    			$result3 = mysql_query($query3) or die("query3 result error".mysql_error());
    		}
    		echo "</ul>";
    	?>
    </div>
    <div id="hidden2">
    	<?php
    		echo "<ul>";
    		while($row3 = mysql_fetch_assoc($result3)){
    			echo "<li onclick=\"toggle('hidden3')\">".$row3['prenom'].'</li>';
    			$query4 = "SELECT * FROM salarie WHERE id =".$row3['id'];
    			$result4 = mysql_query($query4) or die("query4 result error".mysql_error());
    		}
    		echo "</ul>";
    	?>
    </div>
    <div id="hidden3">
    	<?php
    		echo "<ul>";
    		while($row4 = mysql_fetch_assoc($result4)){
    			echo "<li>".$row4['prenom'].'</li>';
    			echo "<li>".$row4['nom'].'</li>';
    		}
    		echo "</ul>";
    	?>
    </div>

 

 

when i click entreprise1 or entreprise2,it shows always e2site1 and e2site2. That means, it always shows the sites corresponding the last element(entreprise2).

 

How can i fix this? Any ideas will be appreciated.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.