Dear Sirs!

I have this php syntax in my <head>.

         <?php
        // MySQL
        mysql_connect("localhost", "fundis_petrol", "petrol123") or die(mysql_error());
        mysql_select_db("fundis_petrol") or die(mysql_error());

        // Table
        $result = mysql_query("SELECT * FROM  `fillingstations` LIMIT 0 , 30")
        or die(mysql_error());  


        // Print

        while($row = mysql_fetch_array($result)){
        echo $row[2];
        }

        ?>  

And I also have this JS (Google Maps API) in my <head>.

    var beaches = [
      ['Miskolci road / Shell Station', <?php echo $row[2]; ?> , 4],
      ['Szabadsag utja / Töltöallomas', 47.559025, 19.281415, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
    ];

But when I try to echo the number with a PHP syntax in my Javascript, the whole map disappears.
I think that it is a wrong way of outputting the number there..

I would be grateful if you could help me,

Tibor :)

Member Avatar for LastMitch

@tibormarias

But when I try to echo the number with a PHP syntax in my Javascript, the whole map disappears.I think that it is a wrong way of outputting the number there..

Is this question related to this other question:

http://www.daniweb.com/web-development/php/threads/440317/pass-php-string-to-js

I'm not sure why you create a new thread when you didn't post any errors in the other thread?

In my opinion, it's a bit different question. Now I have syntax error, in the other thread I needed a simple code. But I accept your query.

Member Avatar for LastMitch

@tibormarias

In my opinion, it's a bit different question. Now I have syntax error, in the other thread I needed a simple code. But I accept your query.

It does look the same

<?php
// MySQL
mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
// Table
$result = mysql_query("SELECT * FROM `fillingstations` LIMIT 0 , 30")
or die(mysql_error());
// Print
while($row = mysql_fetch_array($result)){
echo 'Station name: '. $row[1];
echo 'LatLng: '. $row[2];
echo 'Price: '. $row[3];
}
?> 

-

var beaches = [
['Miskolci road / Shell Station', !!!!Lation!!!! 4],
['Szabadsag utja / Töltöallomas', 47.559025, 19.281415, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];

Explain to me are you back to square 1?

What is in $row[2] ?

"47.559025,19.281415" that is in row[2] without quotation marks.

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.