hi everyone,
I have some problem about simplifying my php code.
At first I want to load my form and then load my information from database if their are any data exists according to the user name.

Actually the problem is,I want to load the js while the information is their.

<?php
$data=mysql_fetch_array[$result];
if($data[0]!=0){
echo"?>
<script>
document.getElementById('text1').value="<?php echo $data[0]";
document.getElementById('text2').value="<?php echo $data[1]";
</script>
<?php
}

?>

thats it..!!

But I want to write it in my js.That will load if data exists.

If their have any alternative way??

Well aside from the fact that it is syntactically incorrect. You aren't terminating the php blocks when you echo. Remember to end them with ?>. Aside from that, when you get the results find the number of results with mysql_num_rows then do a loop.

if im getting this right you are trying to insert some value from php into the js
if so you could do it like this

<?php  echo "<script>some-js-code-with-$varableName</script>";   ?>

also, be careful to escape the quotes in the javascript block if necessary

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.