Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:50:03+00:00 2026-06-18T12:50:03+00:00

I have this: <script type=text/javascript> var dataset = [ 5, 10, 15, 20, 25

  • 0

I have this:

<script type="text/javascript">
var dataset = [ 5, 10, 15, 20, 25 ];

        d3.select("body").selectAll("p")
            .data(dataset)
            .enter()
            .append("p")
            .text("New paragraph!");
</script>

It works. Then I’ve been learning MySQL/PHP and have some data in a tiny database.

<?php
if ( $results ) {
foreach($results as $row) {
    echo $row->eventName . "<br>";
}
} else {
echo 'No rows found.';
}
?>

That works with the rest of it and displays some random event names like Movies, Shopping, Work.

I found this tutorial on how to bring PHP variables into Javascript but can’t figure it out. To simplify instead of trying to figure out the array I even switched to just trying to figure out the data itself but couldn’t even get that. This is what my last attempt was:

    <?php
$php_var = 1;
?>

<script type="text/javascript">
var dataset = <?php echo $php_var; ?>

        d3.select("body").selectAll("p")
            .data(dataset)
            .enter()
            .append("p")
            .text("New paragraph!");
</script>

And then I thought maybe an array would work so tried this

<?php
$php_var = array(
    5, 10, 15, 20, 25);
?>

<script type="text/javascript">
var dataset = $php_var

        d3.select("body").selectAll("p")
            .data(dataset)
            .enter()
            .append("p")
            .text("New paragraph!");
</script>

But also had no luck. Could anyone offer me some advice or point me towards a tutorial on how to get data from PHP into Javascript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:50:04+00:00Added an answer on June 18, 2026 at 12:50 pm

    Try using PHP’s json_encode function, and then embedding the data:

    <?php
        $dataset = array(5, 10, 15, 20, 25);
    ?>
    <script>
        var dataset = <?php echo json_encode($dataset); ?>;
        // ...
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of javascript: <script type=text/javascript> function show_confirm() { var type =
I have this jsonp function: function jsonp(url, callback) { var script = document.createElement(script); script.setAttribute(type,text/javascript);
I have this code: <script type=text/javascript> function js() { var getJs = document.getElementById(jogo); if
I have this snippet: <script type=text/javascript> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-11111111-1']);
I have this code <html> <head> <script src=jquery-1.7.2.min.js type=text/javascript></script> <script src=jquery-ui-1.8.20.custom.min.js type=text/javascript></script> <script type
I have this script $('head').append('<link rel=stylesheet href=css/file1.css type=text/css />'); $('head').append('<link rel=stylesheet href=css/jquery.jscrollpane.css type=text/css />');
The code is like this: var script = document.createElement('script'); //script.type = 'text/javascript'; // do
I have this Javascript snippet in my application to prevent clickjacking: <script language=javascript type=text/javascript>
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have this script: #!/var/home/cherry/opt/perl use Test::More; use DBI; use Test::mysqld; use Data::Dumper; my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.