944,210 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 782
  • PHP RSS
Dec 4th, 2007
0

js problem

Expand Post »
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??
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ruman_eee is offline Offline
10 posts
since Aug 2007
Dec 4th, 2007
0

Re: js problem

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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Dec 6th, 2007
0

Re: js problem

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 Syntax (Toggle Plain Text)
  1. <?php echo "<script>some-js-code-with-$varableName</script>"; ?>
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Dec 6th, 2007
0

Re: js problem

also, be careful to escape the quotes in the javascript block if necessary
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Uploading and resizing images
Next Thread in PHP Forum Timeline: How to properly use tables in db?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC