Jump to content

Help with PHP for relational query


Jeff L

Recommended Posts

Hi all,

 

I have just started learning how to use PHP and I have been developing a website that allows users to query rock climbing routes at different locations.

I have embedded a google map and then query a database which then adds markers to a page. I have been reading a book recently entitled Beginning Google Maps Applications with PHP and Ajax which has been quite good but I am stuck on a piece of code. This code which is below is supposed to query a database and add markers to a map. Can someone please explain the syntax that is used in the 'var markers' section of the code as I can't get it to work.

 

<?php

// Connect to the database

require($_SERVER['DOCUMENT_ROOT'] . '/Cragview/db_login.php');

$conn = mysql_connect($db_host, $db_username, $db_password);

mysql_select_db("cragview", $conn);

 

$north = 20.421865;

$south = 18.281518;

$west = -156.123962;

$east = -150;

 

$query = "SELECT * FROM fcc_location

WHERE longitude < $east

AND latitude < $north

AND longitude > $west

AND latitude > $south";

 

$result = mysql_query($query, $conn);

$joiner = '';

$count = 0;

?>

 

var markers = [

<?php while($row = mysql_fetch_assoc($result)): ?>

<?= $joiner ?>

    {

        'latitude': <?= $row['latitude'] ?>,

        'longitude': <?= $row['longitude'] ?>,

        'address': '<?= addslashes($row['struc_address']) ?>',

        'city': '<?= addslashes($row['struc_city']) ?>',

        'state': '<?= addslashes($row['struc_state']) ?>',

        'height': '<?= addslashes($row['struc_height']) ?>',

        'elevation': '<?= addslashes($row['struc_elevation']) ?>',

        'type': '<?= addslashes($row['struc_type']) ?>',

        'owner': '<?= addslashes($row['owner_name']) ?>'

    }

<?

$joiner = ',';

$count++;

?>

<?php endwhile; ?>

];

 

Any assistance you can give me would be most appreciated.

 

Regards

Jeff Lean

Brisbane, Australia

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.