EntropySink
Technical & Scientific => Programming => Topic started by: Steve on July 11, 2008, 09:29:07 PM
-
I have a need to output the table data to the website after a search, no biggy. The website is coded in html/php using div's and i am going to need to output into a set area and have it scroll to accomodate result size.
After alot of reading it seems you will be told tables is wrong use div, or visa versa. What do you guys think is the best way to approach it?
Here is an example of the raw output: NOTE this is on the swinger domain so caution if at work. Just text.
Clicky (http://www.americanswingersassociation.com/CMDONOTOPEN/print_nertable.php)
Attached is the html file im displaying it in with an example of how it would look. Minor images on it, no biggy.
-
tables for tabular data
-
Going tables means i will most likely have to re-do the page its being used on which is why i wanted another opinion before i went that route. Honestly i think that is probably easier then trying to get it to work the way i want in a div setup
-
Not sure how you'd do tabular data in a div... that just seems messy.
-
Another possible way is to use a dl. That is useful for things like displaying addresses where you could display it tabular but it makes more sense in another format.
-
they certainly do it. For the most part its basically
<div settings>
<?
php code to output data
?>
</div>
-
Another possible way is to use a dl. That is useful for things like displaying addresses where you could display it tabular but it makes more sense in another format.
What im outputting is details of an event, including a description. Would this be a better option?
-
It could be. You could do something like:
<dl>
<dt>Title of 1st event</dt>
<dd>Description</dd>
<dd>Address</dd>
<dt>Title of 2nd event</dt>
<dd>Description</dd>
<dd>Address</dd>
</dl>
Would probably look nicer then just dumping it out as a table.
-
Thats a good idea, ill try that out next time im working on it and see if i can get a nicer result. Thanks :)
-
I'm getting weird formatting with <dl>. I tried it with some basic html output too and its pretty much the same. How do you organize it for desired output?
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<dl>";
echo "<dt>{$field->name}</dt>";
echo "</dl>";
}
//echo "</dl>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
//echo "<dl>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<dl>";
echo "<dd>$cell</dd>";
echo "</dl>\n";
}
-
Dude seriously go look up dl, dt, and dd on the internet and see how they are used.
-
I did, actually at this site (http://www.htmlcodetutorial.com/_DL.html) but even looking at that i dont know if it will work because i need the titles going across the top and the data across under it so a list may not work right
-
i may have to output it in a table and use a div to control it....ugh
-
This is how I would do it personally:
Assuming the following table columns:
title = title of the event
desc = description of the event
streetaddy = street address
city = uh city
state = do I really need to say
zip = yeah if you don't get it by now....
<?php
$result = mysql_query('
SELECT title, `desc`, streetaddy, city, state, zip
FROM events');
if (!$result)
die('Oh fuck');
if (mysql_num_rows($result) == 0)
{
echo '<div>No events</div>';
return;
}
echo '
<dl>';
while ($event = mysql_fetch_assoc($result))
{
echo '
<dt>', $event['title'], '</dt>
<dd class="description">', $event['desc'], '</dd>
<dd class="location">
', $event['streetaddy'], '
', $event['city'], ', ', $event['state'], ' ', $event['zip'], '
</dd>';
}
echo '
</dl>';
mysql_free_result($result);
?>
Then use CSS to make it look pretty (like using pre formating on the address)
-
Thanks mike thats really helpful. It wouldnt be so bad if they had of done this project better from jump street. Plus i never had to make table output pretty before. Appreciate the example :)
-
That makes sense. I dont think it will work for me though because they are pretty set on doing it across like a table instead of listing down. They just want the table to scroll.....ugh your way would be so much easier
-
Tell them to go fuck themselves and do it proper.
-
Yea i just emailed them about it. They have been whining about wanting more space and this is one way to do it...
-
after ten minutes on the phone i finally got him to understand why a list would be better but i got veto'd anyway. Looks like i have to find a way to make the table work. Dammit.
-
Try to do something similar then. Like:
<?php
echo '
<table>
<tr>
<th>Event Title</th>
<th>Description</th>
<th>Address</th>
</tr>';
while ($event = mysql_fetch_assoc($result))
{
echo '
<tr>
<td>', $event['title'], '</td>
<td class="description">', $event['desc'], '</td>
<td class="location">
', $event['streetaddy'], '
', $event['city'], ', ', $event['state'], ' ', $event['zip'], '
</td>
</tr>';
}
echo '
</table>';
Either that or fire them ;)
-
i was thinking something like that with CSS to pretty it up
-
Mike your a genius
-
http://www.americanswingersassociation.com/CM/national_eventreg.php
Its set to auto acroll down when results become longer then the div size. How can i output a line break after each result? I tried a few but it keeps showing up above the div. Something like
Result
__________
Result
but not so much space
-
Empty row:
<tr><td> </td><tr>
If you have multiple tds:
<tr><td colspan="5"> </td><tr>
-
bleh, no need for an empty row. Just use margin or padding on the tr.
-
Bleh small mistake. Have to do it on the td not the tr.
td
{
padding: 0.5em 0;
}
-
Well you could do that too, I suppose.
-
Cool thnx :)
-
Do i get enough control to make the headers line up at the beginning of the data so it all lines up evenly? I want to get the formatting right so i can move on to the search functions, ordering, etc but i know if i show them this style without it at least being lines up they will wanna go right back to that ugly ass table style and its a PIMA
-
huh?
-
like shift the headers left so they alignb with the beginning of the data
-
th
{
text-align: left;
}
-
oh duh me. You would think after all the months spent coding myspace layouts something like this would just occur to me.
-
No effect on it at all. Tried right for a test as well and no change.
-
Ok i got it working.
-
How can i pass information from a php file back to the referring html file? I take the input from the form, and pass it to the php file where the results are found and filtered, but then it needs to go back to the html to be printed out in the td. Would i just do it all in the html file?
Like i know i have seen php forms where they call themselves in the action but thats in a php file. IIRC i can run any php inside an html page by using <?php the code here?> like for example maybe action=" <?php call itsself here ?>" ? I'm just not sure how to get the data results back to echoing them out in the td.
I'm also concerned that doing it all in the html file increases the discovery of directory's and table information with the view source. Not that you couldnt use VS, get the php target file, and then call it directly but it just seems "half ass"
-
You really aren't getting the whole transfer data thing.
Set the action of the form to the same page. Set your method to "post". When you submit the form, the page will submit to itself and all the data will be in the $_POST array so you reference everything from $_POST['variable'].
You cannot execute php from a .html or .htm file unless the server is setup to parse those through the PHP engine. You can combine HTML and PHP in the same page very easily. Just jump in and out of the PHP tags.
I'm starting to get the feeling you're really not doing this right.
-
Set the action of the form to the same page. Set your method to "post". When you submit the form, the page will submit to itself and all the data will be in the $_POST array so you reference everything from $_POST['variable'].
Thats exactly what i was getting at. So i can do it this way, thanks
-
To go along with what ober said here is my general setup for pages:
<?php
/* Common Data */
if (isset($_REQUEST['submit']))
{
/* Process */
showresults();
die;
}
showform();
function showform()
{
?>
<!-- Header stuff -->
<form action="file.php?submit" method="post">
<!-- Form Stuff -->
</form>
<!-- Footer Stuff -->
<?php
}
function showresults()
{
/* Show the results */
}
-
Thats exactly what i did. Im bad at explaining what im trying to do but you and ober hit right on what i was trying to say. I have been going back and forth by jumping in and out of php tags. I just wasnt sure if i could post to itsself the way i wanted. Now im just trying to get the results to return properly i have something out of order or typod somewhere.
-
I wrote my own setup to take in a user supplied zip code, and radius, and then return the results based on that. I used a modified version of the google maps function in regards to finding results based on that input. Its flagging
while ($event = mysql_fetch_assoc($locresult))
So im thinking i did something wrong in the query. Im thinking i am wrong in the use of '>' and '<' but i have seen a few online done just like mine.
$locresult = sprintf("SELECT lat, lng FROM asa_registered_clubs WHERE lat < '$Highlat' AND Lat > '$Lowlat'
AND lng > '$Lowlng' AND Longitude < '$Highlng'",
mysql_real_escape_string($Highlat),
mysql_real_escape_string($Lowlat),
mysql_real_escape_string($$Lowlng),
mysql_real_escape_string($Highlng));
Full code section:
<?php
$radius = $_GET["radiusSelect"];
$zip = $_GET["zip"];
$query = "SELECT zip FROM asa_registered_clubs WHERE zip='$zip'";
$result = mysql_query($query);
if (!$result)
die('Error');
$lat = $row['lat'];
$lng = $row['lng'];
$latRange = $radius / ((6076 / 5280) * 60);
$lngRange = $radius / (((cos($lat * 3.141592653589 / 180) * 6076.) / 5280.) * 60);
$Lowlat = $lat - $latRange;
$Highlat = $lat + $latRange;
$Lowlng = $lng - $lngRange;
$Highlnge = $lng + $lngRange;
$locresult = sprintf("SELECT lat, lng FROM asa_registered_clubs WHERE lat < '$Highlat' AND Lat > '$Lowlat'
AND lng > '$Lowlng' AND Longitude < '$Highlng'",
mysql_real_escape_string($Highlat),
mysql_real_escape_string($Lowlat),
mysql_real_escape_string($$Lowlng),
mysql_real_escape_string($Highlng));
if (mysql_num_rows($result) == 0)
{
echo '<div>No events</div>';
return;
}
echo '
<table>
<tr>
<th>When</th>
<th>Who</th>
<th>What</th>
<th>Where</th>
</tr>';
while ($event = mysql_fetch_assoc($locresult))
{
echo '
<tr>
<td>', $event['date'], ' ', $event['time'], '</td>
<td class="name">
', $event['clubgroupname'], '
<td class="event">
', $event['event'], '
<td class="where">
', $event['city'], '
</td>
</tr>';
}
echo '
</table>';
mysql_free_result($result);
mysql_free_result($locresult);
?>
-
>AND Longitude < '$Highlng'",
should that be lng ?
-
man this might be the ugliest code i ever wrote i got fuckups all over this bitch.
Damn warning thingy. Yea thats one of many. i have GET instead of POST too.
-
Correcting the obvious errors and adding '@' to the while statement (like the google code) removed the errors but its not passing a result. Form is posting properly, im just missing something. I wanted to post updated code to show im completely retarded. Going to keep working at it till i figure it out.
<?php
$radius = $_POST["radiusSelect"];
$zip = $_POST["zip"];
$query = "SELECT zip FROM asa_registered_clubs WHERE zip='$zip'";
$result = mysql_query($query);
if (!$result)
die('Error');
$lat = $row['lat'];
$lng = $row['lng'];
$latRange = $radius / ((6076 / 5280) * 60);
$lngRange = $radius / (((cos($lat * 3.141592653589 / 180) * 6076.) / 5280.) * 60);
$Lowlat = $lat - $latRange;
$Highlat = $lat + $latRange;
$Lowlng = $lng - $lngRange;
$Highlnge = $lng + $lngRange;
$locresult = sprintf("SELECT lat, lng FROM asa_registered_clubs WHERE lat < '$Highlat' AND Lat > '$Lowlat'
AND lng > '$Lowlng' AND lng < '$Highlng'",
mysql_real_escape_string($Highlat),
mysql_real_escape_string($Lowlat),
mysql_real_escape_string($$Lowlng),
mysql_real_escape_string($Highlng));
if (mysql_num_rows($result) == 0)
{
echo '<div>No events</div>';
return;
}
echo '
<table>
<tr>
<th>When</th>
<th>Who</th>
<th>What</th>
<th>Where</th>
</tr>';
while ($event = @mysql_fetch_assoc($locresult))
{
echo '
<tr>
<td>', $event['date'], ' ', $event['time'], '</td>
<td class="name">
', $event['clubgroupname'], '
<td class="event">
', $event['event'], '
<td class="where">
', $event['city'], '
</td>
</tr>';
}
echo '
</table>';
mysql_free_result($result);
//mysql_free_result($locresult);
?>
-
My flow makes no sense at all. My select statement for the zip is pointless. I'm taking a radius and then trying to pull lat and lang based on a zip but that isnt going to give me a list of results within a radius. I'm just plain way off. I need to scrap all of this and start over.
-
Even using the google code exactly (just replacing the xml outputting with echo) isnt working. I think its because its all in one file. Google uses it as two seperate files i may just have to do that. i just have to figure out how to pass the variables back to the html from the php.
all i want is results based on radius of a given zip code this shouldnt be such a headache
-
http://www.phpclasses.org/browse/package/3156.html - there are a million classes out there that do this for you. Just do a search.
-
fukin a. this must be one of those "didnt quite get it right on google" cases cuz i was searching all damn day. Thnx
-
I dont have enough knowledge of php to get that working. The way its passing data is completely new to me, but im saving it because i do want to learn and understand it. im working on trying to find a way to use the google maps system. It already does exactly what i want, it just outputs to xtml and passes to crate the map. If i can harness the output before it goes xml the way i want i can use it.
I thought maybe i can collect it, post it to a table, then call it in the output. But i would need a way to "dump" the data when i was done with it. and multiple users at once i dont think that would work.
-
I'm having trouble even understanding what you're trying to do. Maybe if you can explain the problem in plain English (e.g. i want to find all of the events for over-tanned 50 year olds oiling each other up within a 50 mile radius of my house), someone will be a lamb and write it for you.
no offense, but it seems your at the point that someone is going to have to do this for you. Cut and pasting other's code, especially when there is little understanding of what the code does, is only going to work in the most simple of cases...like a contact form...a bad contact form that easily exploited by spammers...
-
deleted
-
heres the zip file of both files. This part is all new to me and it would be EASIER to pay someone to do it for me, but then i wont learn anything. Mike and Ober have been a tremendous help through the whole project and i have learned a ton because of it. I owe them christmas presents this year lol.
-
deleted
-
Got it. The problem is the data is not posting from the first file to the next. i set the three variables in the php2 file manually and viola, working output. So i should be able to get it working now once i find the issue and set it up the right way.
-
deleted
-
Ok i think im going to just scrap it, and learn to use a class like the one ober posted. It just seemed like it would be so much easier to use a system i already had in place. I really dont see why i cant modify this to work >_<
-
Ok so i started anew. I have the form, the variables are posting, and i have the query for filtering out the results. What i cant figure out is how factor the given zip code and the distance into the query. That is the part google handled, and the examples online are sloppy or dont completely differently and dont seem to work properly.
$query = "SELECT date, time, city, event, clubgroupname, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM asa_eventregister HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20";
This query, if im following it right, takes out the data im going to be displaying and the lat and lng for the math part. The 3959 is the earths radius. I have no flippin clue what the '%s' is or means. lat and lng are the lattitude and longitude from the table. Then the query takes in the results that fall in the distance.
What this query doesnt know is the zip code or what my distance requirements are....and i have no idea how to tell it.
<?php
include("Connections/establish_dbconn.php");
mysql_select_db("$database_ASA") or die(mysql_error());
$zip = $_POST["zip"];
$radius = $_POST["radius"];
$query = "SELECT date, time, city, event, clubgroupname, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM asa_eventregister HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{
$date = $row['date'];
$time = $row['time'];
$city = $row['city'];
$event = $row['event'];
$clubgroupname = $row['clubgroupname'];
echo $date;
echo $time;
echo $city;
echo $event;
echo $clubgroupname;
}
?>
-
This is an exceprt from the mysql pdf i have been reading. It helped make sense, but note that the example shows a pre-defined original lat and lng. I cant set it static like that
-
I think i may just have to surrender this part to a third party. I have never found something i couldnt wrap my head around (even if it takes some help to get there) but between the other jobs i have and the deadlines i cant get my fucking brain to knock this fucking search out.
-
oh i am a fucking moron. i dont even have a DB of the zip codes with long and lat.....i forgot google was handling that, all i have is the clubs. well gee that would be a fucking start
-
ok i wrote the flow/program out on paper and it helped me, i think im off to a much better start. I'm not sure i did this query right but it looks like it does on google hits. The first echo works, so the form is working. The echo after the query isnt working so my query must be done incorrectly.
$zip = $_POST["zip"];
$radius = $_POST["radius"];
echo $zip;
echo $radius;
$sql = "SELECT latitude,longitude FROM zip AS latitude, longitude WHERE zip='$zip'";
$distance_lookup_slop_miles = 5;
echo $latitude;
echo $longitude;
-
That query shouldn't even run, doesn't it give you an error? You can't compare a table to a value. zip is a table (or at least it looks like it from your query). You need to access the zip field from the zip table (or however you have it named). Something like:
SELECT latitude, longitude FROM ziptable WHERE ziptable.zipcode = $zip
-
I bet he has a table called zip which has a column called zip. Bad bad bad
-
Mikes right. The column was originally 'zip code' but it wasnt working so i figured it was the space and made it just 'zip'. And no, there wasnt any errors i checked.
So i rename the column zipcode and do it as
$sql = "SELECT latitude,longitude FROM zip AS latitude, longitude WHERE zip.zipcode=$zip";
-
Now the errors arrived:
Notice: Undefined variable: latitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 40
Notice: Undefined variable: longitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 41
Notice: Undefined variable: latitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 45
Notice: Undefined variable: latitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 46
Notice: Undefined variable: latitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 48
Notice: Undefined variable: longitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 50
Notice: Undefined variable: longitude in /home/content/i/y/q/iyq2havfun/html/CM/testform.php on line 51
-
How are you pulling those variables out?
-
In the query. Unless im confusing the use of "AS" which wouldnt suprise me
-
Well from your snippet of code you aren't doing the query nor are you fetching the results.
-
somehow in my copy and paste i missed code. Dont ask how, we'll never figure me out:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
include("Connections/establish_dbconn.php");
mysql_select_db("$database_ASA") or die(mysql_error());
$zip = $_POST["zip"];
$radius = $_POST["radius"];
echo $zip;
echo $radius;
$sql = 'SELECT latitude,longitude FROM zip AS latitude, longitude WHERE zip.zipcode=$zip';
$distance_lookup_slop_miles = 5;
$zipresult = mysql_query($sql);
if (!$zipresult) {
die("Invalid query: " . mysql_error());
}
while ($ziprow = mysql_fetch_assoc($zipresult))
{
echo $latitude;
echo $longitude; }
$delta_latitude = (($radius + $distance_lookup_slop_miles) / 69.172);
$lat1 = $latitude + $delta_latitude;
$lat2 = $latitude - $delta_latitude;
$delta_longitude = (($radius + $distance_lookup_slop_miles) / (cos($latitude) * 69.172));
$long1 = $longitude + $delta_longitude;
$long2 = $longitude - $delta_longitude;
$query = "SELECT date, time, city, event, clubgroupname, lat, lng FROM asa_eventregister WHERE
lat <= $lat1 AND lat >= $lat2 AND lng <= $long1 AND lng >= $long2";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{
$date = $row['date'];
$time = $row['time'];
$city = $row['city'];
$event = $row['event'];
$clubgroupname = $row['clubgroupname'];
echo $date;
echo $time;
echo $city;
echo $event;
echo $clubgroupname;
}
?>
-
ok those errors are gone now. Above code is kicking an error after the second query
"Invalid query: Table 'asa_db.longitude' doesn't exist"
It's not echoing out the longitude and latitude after the first query and im not sure if these are related. I dont even know what i did to make the others go away
-
>FROM zip AS latitude, longitude
This is wrong. it says use table zip and call it latitude , also use table longitude (cross product those tables). Just remove that whole AS statement and use the proper php crap to load the results into your variables (I don't know that part).
-
Okie can do, thanks
-
hmmm
"Invalid query: Unknown column '$zip' in 'where clause'"
For some reason no matter how i order it (i used the suggested method see code) is thinks the $zip variable is a column instead of what its looking for. Thats odd....
-
<?php
while ($ziprow = mysql_fetch_assoc($zipresult))
{
echo $latitude;
echo $longitude; }
?>
Think about this now. How is the value suppose to magically jump from $ziprow['lat'] to $latitude and $ziprow['lng'] to $longitude?
-
i thought i was assigning it in the AS statement. Now thats gone its
while ($ziprow = mysql_fetch_assoc($zipresult))
{
$latitude = $row['lat'];
$longitude = $row['lng'];
echo $latitude;
echo $longitude; }
-
Think i got it, brb
-
ok its working sorta i think im good now. THINK lol
-
OK all the checks and math are working, outputting correctly, etc. The data chain gets broken at the query to check the events DB for results within the lat/lng range. Since i misunderstood the use of "AS" im betting im using "AND" incorrectly.
$query = "SELECT * FROM asa_eventregister WHERE lat <= $lat1 AND lat >= $lat2 AND lng <= $long1 AND lng >= $long2";
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
include("Connections/establish_dbconn.php");
mysql_select_db("$database_ASA") or die(mysql_error());
$zip = $_POST["zip"];
$radius = $_POST["radius"];
$sql = "SELECT latitude,longitude FROM zip WHERE zipcode='$zip'";
$zipresult = mysql_query($sql);
if (!$zipresult) {
die("Invalid query: " . mysql_error());
}
while ($ziprow = mysql_fetch_assoc($zipresult))
{
$latitude = $ziprow['latitude'];
$longitude = $ziprow['longitude'];
}
$delta_latitude = ($radius / 69.172);
$lat1 = $latitude + $delta_latitude;
$lat2 = $latitude - $delta_latitude;
$delta_longitude = ($radius / (cos($latitude) * 69.172));
$long1 = $longitude + $delta_longitude;
$long2 = $longitude - $delta_longitude;
$query = "SELECT * FROM asa_eventregister WHERE lat <= $lat1 AND lat >= $lat2 AND lng <= $long1 AND lng >= $long2";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{
$date = $row['date'];
$time = $row['time'];
$city = $row['city'];
$event = $row['event'];
$clubgroupname = $row['clubgroupname'];
echo $date;
echo $time;
echo $city;
echo $event;
echo $clubgroupname;
}
?>
-
Query looks fine, are you getting an error or just no data? Are you sure there's data in the DB for the test your running?
-
No errors its just not echoing the rows in the final while statement. And yes the DB contains data and contains matches.
-
its an error in the math. Same code as above, entering the zip code with a 10mile radius i get the following vaariable values:
lat1 = 0.14456716590528
lat2 = -0.14456716590528
long1 = 0.14456716590528
long2 = -0.14456716590528
All the same just one has the "-" on it.
-
How is it that both delta variable compute correctly, but then the long and lat computations all match.....wth
$delta_latitude = ($radius / 69.172);
$lat1 = ($latitude + $delta_latitude);
$lat2 = ($latitude - $delta_latitude);
$delta_longitude = ($radius / (cos($latitude) * 69.172));
$long1 = ($longitude + $delta_longitude);
$long2 = ($longitude - $delta_longitude);
-
I dont see an issue with $var = $var1 + $var2; but its not working correctly. The data is correct before the computation....wth
-
Run this and paste the results please:
echo '<pre>';
var_dump($radius);
var_dump($latitude)
var_dump($longitude);
$delta_latitude = ($radius / 69.172);
var_dump($delta_latitude);
$lat1 = ($latitude + $delta_latitude);
$lat2 = ($latitude - $delta_latitude);
var_dump($lat1);
var_dump($lat2);
$delta_longitude = ($radius / (cos($latitude) * 69.172));
var_dump($delta_longitude);
$long1 = ($longitude + $delta_longitude);
$long2 = ($longitude - $delta_longitude);
var_dump($long1);
var_dump($long2);
echo '</pre>';
-
string(2) "10"
string(13) " " 26.579862""
string(13) " " -82.00227""
float(0.14456716590528)
float(0.14456716590528)
float(-0.14456716590528)
float(0.14456716590528)
float(0.14456716590528)
float(-0.14456716590528)
-
String (13) + (13) are correct values.
-
Do you see the problem yet?
-
they shouldnt be floats, should they? They were for the google maps table, im betting they use float for the geocode but then convert them to a string?
-
No, strings are fine but look at the value closely and compare them to the outputs of the floats
-
The strings show (13) but they arent, and the floats appear to be re-arranged versions of the strings. What i mean is the floats only contain nuumbers that appear in the strings. Hope this is right im bad with numbers/math so im half guessing
-
well...theres 4's in there too.
-
Sorry, should have had you compare it to string(2).
string(2) "10" -> String containing: 10
string(13) " " 26.579862"" -> String containing: " 26.579862"
string(13) " " -82.00227"" -> String containing: " -82.00227"
-
Im not getting it. The "10" is the radius given, and the two strings are the correct lat and long from the DB.
-
i changed the 10 to 200 just for a second example.
string(3) "200"
string(13) " " 26.579862""
string(13) " " -82.00227""
float(2.8913433181056)
float(2.8913433181056)
float(-2.8913433181056)
float(2.8913433181056)
float(2.8913433181056)
float(-2.8913433181056)
-
/me pulls out the clue bat
Here's a hint: $radius is fine
-
extra " "? im going to go get coffee i think i need it
-
there we go
-
ahhhh SHIT the whole zip db has "" around the data i never even noticed it. Hey out of curiousity, when viewing the table summary in phpmyadmin it says "Overhead: 76B".....whats overhead in this case?
-
Ok it works now. Thanks mikey, now i gotta fix the whole DB.
-
Not sure exactly what overhead is (should probably take that DB class) but from searching it appears to be a measure of additional resources needed to query that table. Generally running optimize on the table reduces/removes the overhead.
-
Ok i'll look into it
-
Is there a better way to remove the quotes then by hand? I have the db as a text file and using replace keeps crashing it.
-
What I would do is something like (important note: I'm going to assume that the primary index is only one column called ind)
<?php
$arr = array();
$result = mysql_query('SELECT ind, lat, long FROM zip');
while ($row = mysql_fetch_assoc($result))
{
// 2 to remove (space)" at the beginning and -1 to remove " at the end
$lat = substr($row['lat'], 2, -1);
$long = substr($row['long'], 2, -1);
mysql_query("UPDATE zip SET lat = '$lat' AND long = '$long' WHERE ind = '$row[ind]' LIMIT 1");
}
mysql_free_result($result);
?>
throw that in a PHP file and run it ONCE AND ONLY ONCE!
-
so can i set the zip col to primary and repleace ind with zip? Thnx appreciate it
-
Replace ind with whatever the column of the primary index is. If the primary index takes more then one column you'll need to get them in the select and add those to the WHERE condition
-
i only have one primary, and thats "zipcode". code didnt update anything i must have adjusted it wrong. Table is zip, colums are zipcode, longitude, latitude
<?php
include("Connections/establish_dbconn.php");
if (!mysql_select_db($database_ASA))
die("Can't select database");
$arr = array();
$result = mysql_query('SELECT zipcode, latitude, longitude FROM zip');
while ($row = mysql_fetch_assoc($result))
{
// 2 to remove (space)" at the beginning and -1 to remove " at the end
$lat = substr($row['latitude'], 2, -1);
$long = substr($row['longitude'], 2, -1);
mysql_query("UPDATE zip SET latitude = '$lat' AND longitude = '$long' WHERE zipcode = '$row[zipcode]' LIMIT 1");
}
mysql_free_result($result);
?>
-
hmm try this for the loop (as a test)
while ($row = mysql_fetch_assoc($result))
{
// 2 to remove (space)" at the beginning and -1 to remove " at the end
$lat = substr($row['latitude'], 2, -1);
$long = substr($row['longitude'], 2, -1);
$row['lat'] = $lat;
$row['long'] = $long;
echo '<pre>'; var_dump($row); echo '</pre>';
}
See if the output is making the change or not. I'm not 100% on the substr because I've never done it like that but from a quick read of the man page it should work.
-
tons of output heres two i grabbed for the example.
array(5) {
["zipcode"]=>
string(5) "35049"
["latitude"]=>
string(13) " " 33.963435""
["longitude"]=>
string(13) " " -86.59540""
["lat"]=>
string(10) " 33.963435"
["long"]=>
string(10) " -86.59540"
}
array(5) {
["zipcode"]=>
string(5) "35051"
["latitude"]=>
string(13) " " 33.201789""
["longitude"]=>
string(13) " " -86.61584""
["lat"]=>
string(10) " 33.201789"
["long"]=>
string(10) " -86.61584"
}
-
ok change the 2 in the substr to a 3 and use this in place of the query in the loop
$result = mysql_query("UPDATE zip SET latitude = '$lat' AND longitude = '$long' WHERE zipcode = '$row[zipcode]' LIMIT 1");
if (!$result)
echo 'Query error ', mysql_errno(), ': ', mysql_error(), '<br />';
else
echo 'Query changed ', mysql_affected_rows(), '<br />';
-
i musta messed up
<?php
include("Connections/establish_dbconn.php");
if (!mysql_select_db($database_ASA))
die("Can't select database");
$arr = array();
$result = mysql_query('SELECT zipcode, latitude, longitude FROM zip');
while ($row = mysql_fetch_assoc($result))
{
// 2 to remove (space)" at the beginning and -1 to remove " at the end
$lat = substr($row['latitude'], 3, -1);
$long = substr($row['longitude'], 3, -1);
$row['lat'] = $lat;
$row['long'] = $long;
$result = mysql_query("UPDATE zip SET latitude = '$lat' AND longitude = '$long' WHERE zipcode = '$row[zipcode]' LIMIT 1");
if (!$result)
echo 'Query error ', mysql_errno(), ': ', mysql_error(), '<br />';
else
echo 'Query changed ', mysql_affected_rows(), '<br />';
}
mysql_free_result($result);
?>
Query changed 1
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/y/q/iyq2havfun/html/CM/update.php on line 11
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/content/i/y/q/iyq2havfun/html/CM/update.php on line 26
-
DOH! That is my bad
in the query in the loop change $result to $result2
-
i thought that was odd but what do i know LOL.
-
After about 20min it changed all the "latitude" fields to "0" and thats it lol.
-
Well at least it is a valid number ;)
Shrug, I would probably just try a reimport making sure those two columns are properly formatted.
-
yea im going to screw it with it tomm. Appreciate all the help
-
Eh i keep trying to get the php to work but i think im going to need to do it by hand
-
i cant do this by hand i been here for 2 hours im not even out of the AL's yet
-
Just out of curiousity i see
$arr = array();
but i dont even see it used?
-
Heh left over from my orignal idea. Orignally I was just gonna do a replace into but then remembered it would need to select all the information and I didn't want to do that.
-
I figured it was left over but i wanted to check. I really dont see why it wouldnt/doesnt work. The code matches the DB structure, the zipcode is set to primary......yet it just makes the latitude columb 0's it doesnt do anything else.
-
Looking at php.org though i think it should be a "2" and not a "3"
-
In the substr? Now it should be a 3. You want to remove {space}"{space} at the beginning. Email me the file that you want to import and I'll fix it up for ya. mikemill @ gmail.com
-
Sent, appreciate it.
-
Should be coming back. Gmail give me a weird popup so I'm hoping it got sent. Let me know if you don't get it.
-
Oh and if you don't have a text editor that can do regular expressions get one that does. It seriously helps A LOT
-
Got it :)
i have been using notepad tbh. What do you guys use? Most of my code gets done in Dreamweaver because i like the software for it. The whole WYSIWYG idea is gay, but for doing actual code i like the features and the layout.
-
Now heres something odd. I added a few entries to the events table with correct zip/lat/lang with the same format as the previous entry, and the search function doesnt return any matches. It works for the other zip code testing, but not this zip. Everything lines up and matches between the two db's. Man this is annoying LOL
-
I personally use editplus. Worth the license fee IMO.
-
I'll download that and check it out. I think i found the latest issue im running some checks now b/c there no reason the code wouldnt work so i think i did a dupe in the DB on accident.
-
No duplicates in either DB (i had index set so makes sense). I have the event data setup the same for both zip code results, yet one returns properly and the other test fails. The code obviously works, the data matches between the data bases.....why in the hell wouldnt it work?
I'm going to keep toying with it if you guys get bored let me know what you need to see and ill post it up.
-
Heres a snapshot of the zip table where the data im using to test is located, as well as a ss of the events table (i used print view since its a wide view).
What i dont get is using "33914" returns the search results as expected. Using "35004" returns nothing. Yet theres no reason that it should not. I tried re-arranging where the row is located in the zip DB and no difference. The search only goes by zipcode, lat, and lng so nothing else should matter. I dont get why the code works for one and not the other. I even deleted the "33914" entry from the events table and it still did not return the "35004" result.
The "zip" table uses "zipcode" as the primary key. The event table does not have a primary, as there may be multiple entries for each zip and/or club so i really cant define a primary.
Note that the lat/lng rounds when entered into the evnts table. BUT this doesnt seem to affect the 33914 return so why would it affect the other? In the zips table lat/lng are set varchar(20) and in the events table they are float(10,6). Perhaps i should drop the float setting on the events table and do them the same. I'm not geocoding based off either table im using fetch for that so float really isnt needed.
-
OMG... are you seriously still working on this thing?
-
Yea i know. It works, it just doesnt work right LOL. It doesnt make any goddamn sense.
-
IT MAKES NO FUCKING SENSE. I can arrange the data in the tables in any order, using multiple f'n zip codes and ONLY 33914 ever returns results. WHAT IN THE FUCK HOW CAN THAT BE???
jesus christ why me
-
It's the fucking math. I need a slop factor.
-
Got it, thank fucking god.