0

I want to Create div dynamically with unique id.. base on id we need to get values form the database ..but here can get id but divTag.innerHTML= not getting id to execute my sql query please help me out thanks in adnvce

.dynamicDiv {
width:200px;
height:100px;
border:solid 1px #c0c0c0;
background-color:#e1e1e1;
font-size:11px;
font-family:verdana;
color:#000;
padding:5px;
}

.dynamicDiv{ float:left;}


</style>

<script type="text/javascript" language="javascript">
function createDiv($id)
{

        var id =$id;
        var divTag = document.createElement("div");
        var id =$id;
        divTag.id = "div1";
        divTag.setAttribute("align","center");
        divTag.style.margin = "100px auto";
        divTag.className ="dynamicDiv";
        divTag.innerHTML = "<?php $sql =mysql_query("SELECT * FROM TABLE WHERE ID='$id'");
        $res = mysql_fetch_array($sql);
        print_r($res);  
        ?>";
        document.body.appendChild(divTag);
        }

</script>
</head>
<body style="float:left;">
<div  style="float:left;">
     <b>Click this button to create div element dynamically</b>
    <input id="btn1" type="button" value=
"create div" onClick="createDiv('<?php echo rand(); ?>');" />

2
  • javascript is executed on client side whereas php on server side so not going to work. Commented Nov 21, 2012 at 12:53
  • 1
    You will need to use ajax to get the record. Commented Nov 21, 2012 at 12:53

1 Answer 1

4

You can not bring data from server with sending call to server, You can use jquery ajax to bring the data and pass the id to filter the data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.