JAvaSCript Encapsulated to PHP

how can i write php with javascript code pls help..

sample idea like this..
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
echo "<TABLE BORDER=\"0\" ONCLICK=\"Event()\">\n";
while($row = mysql_fetch_array($result)) {
    echo "<TR><TD>" . $row['stuff'] . "</TD></TR>\n";
echo "</TABLE>\n";

i call javascript onclick event function, did i write it corretly? -->>ONCLICK=\"Event()\"

pls help..
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Change it to


And you can test this in javascript easily

  function Event(){
  var ln;
  var test='tum te tum te tum';
  ln = "<table border='0' onMouseDown=\"Event()\">";
  ln+= "<tr><td>"+ test +"</td></tr>";

The difference is that onMouseDown defines a handler for the entire table, if you use onclick you have to write it for each element that you need to be clickable ... afaik

In your echo string you can use single quotes for your HTML attributes which makes it look neater but you have to use \" for the function related things, like my example above, its not entirely nessecery to use the \n either.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
another point to remember:
javascript is case sensitive. onClick can't be substituted for ONCLICK.
try that and see if your code works ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.