Jump to content

[SOLVED] How can i list row from my SQL database based upon a User Form Query?


Recommended Posts

What i have is a bunch of address information in a SQL database (city / state / zipcode / longlat) etc.. that I am using with the google map API to generate a map based on that SQL data.  A feature i'd like to add is to be able to have is a field where the user can input a zipcode and then have it output and map only the address info with that zipcode.  Does anybody have an example of something which does that? I'm having a hard time putting it together.

 

I realize i can do something like this:

 

$result = mysql_query("SELECT * FROM usefuldata WHERE Zipcode=23507 ",$link);

 

But how can i make it so that the Zipcode variable above is changed by a user input?

 

This is the relevant code i've got:

 

----loads the map----

 

<html>

<head>

<title>The Map</title>

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAoTab4L8nRAD2RasQZtmD1hSRQosRN6DdNziGgU6CSoC9_MkdlRSYMg1lPRvjkh91ItG3vo4SXHNy-A" type="text/javascript"></script>

</head>

<body>

<p align="center"><strong>What, where.</strong></p>

<div id="map" style="width: 800px; height: 600px"></div>

 

 

 

 

<div align="center">

  <script type="text/javascript">

//<![CDATA[

 

var map = new GMap2(document.getElementById("map"));

map.addControl(new GLargeMapControl());

map.addControl(new GMapTypeControl());

map.addControl(new GScaleControl());

map.setCenter(new GLatLng(36.884952, -76.286684), 15, G_NORMAL_MAP);

 

// Creates a marker whose info window displays the given number

function createMarker(point, number)

{

var marker = new GMarker(point);

// Show this markers index in the info window when it is clicked

var html = number;

GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});

return marker;

};

 

 

<?php

$link = mysql_connect("host", "login", "pass") or die("Could not connect: " . mysql_error());

mysql_selectdb("data",$link) or die ("Can't use dbmapserver : " . mysql_error());

 

$result = mysql_query("SELECT * FROM usefuldata WHERE Zipcode=23507 ",$link);

if (!$result)

{

echo "no results ";

}

while($row = mysql_fetch_array($result))

{

echo "var point = new GLatLng" . $row['latlon'] . ";\n";

echo "var marker = createMarker(point, '" . addslashes($row['data']) . "');\n";

echo "map.addOverlay(marker);\n";

echo "\n";

}

 

echo "map.setCenter(point);\n";

 

mysql_close($link);

?>

 

//]]>

</script>

 

</div>

</body>

</html>

----------------------------section that stores the data in my database-------

 

<html>

<head>

<meta

http-equiv="refresh" content="0; url=http://jaswes.ifastnet.com/xloadmapx.php">

</head>

<body>

 

 

<?php

$con = mysql_connect("host", "login", "pass");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("data", $con);

 

 

$sql="INSERT INTO usefuldata (Rent, Address, City, State, Zipcode,latlon)

VALUES

('$_POST[html_rent]','$_POST[html_address]','$_POST[html_city]','$_POST[html_state]','$_POST[html_zipcode]',  '$_POST[html_latlon]' )";if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added";mysql_close($con)

?>

 

<br>

<br>

<a href="website">Click for Map!</a>

 

 

</html>

</body>

 

 

 

Quick Simple cheap idea

 

 

just say your file is called index.php

 

make this change

<?php

$ZIP= $_GET['ZIP']; //<--Add
$result = mysql_query("SELECT * FROM usefuldata WHERE Zipcode=$ZIP",$link); //<--Change to

?>

 

and load it up like this

 

index.php?ZIP=33566

I'm not sure exactly how i'd make this suggestion user friendly?

 

I'd like a form or something on the actual page itself which would update it.

 

I'm not sure how i'd pass that link index.php?ZIP=33566 to the site to do what you're suggesting.

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.