Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Coordinate search

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Coordinate search

Postby paulhesketh » Sat Apr 06, 2013 4:53 am

Hi, looking for help with a small project for a game I play.

Intro

Game board x=400 y=400 squares. Total of 320,000 squares.

Each square has a Name. And a coordinate assigned to it

I have a database containing all names and x/y coordinates

What I need to do is find a way to display the results of the 25 squares around a particular coordinate, each direction)

Example - if I am at x100 y100, it will display all the names of squares 25 north, south, east and west total of 2601 names

What I have so far

xysearch.html

Code: Select all

<form action="xysearch.php" method="post">
  <label>X Coord
  <input type="text" name="fld_x" />
</label>
  <label>Y Coord
  <input type="text" name=fld_y" />
  </label>
  <input type="submit" value="Search" />
</form>



xysearch.php

Code: Select all

<?php

$x = $_POST['fld_x'];
$y = $_POST['fld_y'];

mysql_connect ("localhost","user","pass")  or die (mysql_error());
mysql_select_db ("my_database");


$res = mysql_query("select * FROM my_table WHERE (x between $x-25 AND $x+25) AND (y BETWEEN $y-25 AND $y+25)");


 
 echo "<table border='1' align='center' cellpadding='5'>";
        echo "<tr> <th>City Name</th> <th>X</th> <th>Y</th> </tr>";

        // loop through results of database query, displaying them in the table
        while($row = mysql_fetch_array( $res )) {
               
                // echo out the contents of each row into a table
      echo "<tr>";
      echo '<td>' . $row['city'] . '</td>';
                echo '<td>' . $row['x'] . '</td>';
      echo '<td>' . $row['y'] . '</td>';
                echo "</tr>";
        }

        // close table>
        echo "</table>";
?>




It's not showing anything so I guess I have something wrong somewhere, any ideas please. With thanks.
paulhesketh
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Apr 06, 2013 4:34 am

Re: Coordinate search

Postby johnj » Sun Apr 07, 2013 9:19 pm

1.Check if appropriate data is there in the table so that the sql query can pick it.

2. Next, display (print) he query result and see if the code is able to pick the data.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron