0

I have a php query like so:

<?php
    $query = "SELECT * FROM " . $usertable . " ORDER BY fname;";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){
        echo '<option value="' . $row['pkid'] . '">' . $row['fname'] . ' ' . $row['lname'] . '</option>';
    }
?>

Within this same .php file I have some javascript. All I would like to do is return $row['fname'] as a a javascript variable.

Is this possible?

2

1 Answer 1

2

If you want to output the PHP variable in a JavaScript variable you could do something like this -

echo '<script>var name+' . $row['pkid'] . ' = ' .$row['fname'] . ';</script>';

This would give you a uniquely named variable for each row.

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.