EntropySink

Technical & Scientific => Programming => Topic started by: Steve on July 11, 2008, 09:29:07 PM

Title: What is the proper way?
Post 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.
Title: Re: What is the proper way?
Post by: Mike on July 11, 2008, 09:30:45 PM
tables for tabular data
Title: Re: What is the proper way?
Post by: Steve on July 11, 2008, 09:42:55 PM
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
Title: Re: What is the proper way?
Post by: ober on July 12, 2008, 01:38:02 PM
Not sure how you'd do tabular data in a div... that just seems messy.
Title: Re: What is the proper way?
Post by: Mike on July 12, 2008, 02:00:03 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 12, 2008, 02:00:41 PM
they certainly do it. For the most part its basically

<div settings>
<?
php code to output data
?>
</div>

Title: Re: What is the proper way?
Post by: Steve on July 12, 2008, 02:01:13 PM
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?
Title: Re: What is the proper way?
Post by: Mike on July 12, 2008, 02:03:42 PM
It could be.  You could do something like:

Code: [Select]
<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.
Title: Re: What is the proper way?
Post by: Steve on July 12, 2008, 02:06:21 PM
Thats a good idea, ill try that out next time im working on it and see if i can get a nicer result. Thanks :)
Title: Re: What is the proper way?
Post by: Steve on July 13, 2008, 01:48:03 PM
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?

Code: [Select]
// 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";


}
Title: Re: What is the proper way?
Post by: Mike on July 13, 2008, 03:10:34 PM
Dude seriously go look up dl, dt, and dd on the internet and see how they are used.
Title: Re: What is the proper way?
Post by: Steve on July 13, 2008, 03:25:19 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 13, 2008, 03:27:03 PM
i may have to output it in a table and use a div to control it....ugh
Title: Re: What is the proper way?
Post by: Mike on July 13, 2008, 05:17:41 PM
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....

Code: [Select]
<?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)
Title: Re: What is the proper way?
Post by: Steve on July 13, 2008, 05:19:28 PM
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 :)
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 12:34:13 PM
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
Title: Re: What is the proper way?
Post by: Mike on July 14, 2008, 12:35:03 PM
Tell them to go fuck themselves and do it proper.
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 12:38:05 PM
Yea i just emailed them about it. They have been whining about wanting more space and this is one way to do it...
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 01:14:44 PM
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.
Title: Re: What is the proper way?
Post by: Mike on July 14, 2008, 01:36:23 PM
Try to do something similar then.  Like:

Code: [Select]
<?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 ;)
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 01:37:25 PM
i was thinking something like that with CSS to pretty it up
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 01:52:16 PM
Mike your a genius
Title: Re: What is the proper way?
Post by: Steve on July 14, 2008, 05:25:23 PM
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
Title: Re: What is the proper way?
Post by: ober on July 15, 2008, 09:26:52 AM
Empty row:
Code: [Select]
<tr><td>&nbsp;</td><tr>
If you have multiple tds:
Code: [Select]
<tr><td colspan="5">&nbsp;</td><tr>
Title: Re: What is the proper way?
Post by: Mike on July 15, 2008, 09:29:43 AM
bleh, no need for an empty row.  Just use margin or padding on the tr.
Title: Re: What is the proper way?
Post by: Mike on July 15, 2008, 09:48:53 AM
Bleh small mistake.  Have to do it on the td not the tr.
Code: [Select]
td
{
padding: 0.5em 0;
}
Title: Re: What is the proper way?
Post by: ober on July 15, 2008, 10:37:47 AM
Well you could do that too, I suppose.
Title: Re: What is the proper way?
Post by: Steve on July 15, 2008, 12:58:52 PM
Cool thnx :)
Title: Re: What is the proper way?
Post by: Steve on July 15, 2008, 03:34:48 PM
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
Title: Re: What is the proper way?
Post by: Mike on July 15, 2008, 04:15:52 PM
huh?
Title: Re: What is the proper way?
Post by: Steve on July 15, 2008, 04:21:42 PM
like shift the headers left so they alignb with the beginning of the data
Title: Re: What is the proper way?
Post by: Mike on July 15, 2008, 04:37:37 PM
Code: [Select]
th
{
  text-align: left;
}
Title: Re: What is the proper way?
Post by: Steve on July 15, 2008, 04:51:22 PM
oh duh me. You would think after all the months spent coding myspace layouts something like this would just occur to me.
Title: Re: What is the proper way?
Post by: Steve on July 15, 2008, 04:58:58 PM
No effect on it at all. Tried right for a test as well and no change.
Title: Re: What is the proper way?
Post by: Steve on July 16, 2008, 02:45:57 PM
Ok i got it working.

Title: Re: What is the proper way?
Post by: Steve on July 16, 2008, 03:19:44 PM
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"
Title: Re: What is the proper way?
Post by: ober on July 16, 2008, 04:26:29 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 16, 2008, 04:44:42 PM
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
Title: Re: What is the proper way?
Post by: Mike on July 16, 2008, 04:49:58 PM
To go along with what ober said here is my general setup for pages:

Code: [Select]
<?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 */
}
Title: Re: What is the proper way?
Post by: Steve on July 16, 2008, 05:07:53 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 11:32:14 AM
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

Code: [Select]
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.

Code: [Select]
$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:

Code: [Select]
<?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);
?>
Title: Re: What is the proper way?
Post by: Perspective on July 17, 2008, 04:29:32 PM
>AND Longitude < '$Highlng'",

should that be lng ?
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 04:36:31 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 04:47:34 PM
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.

Code: [Select]
<?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);
?>
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 04:59:33 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 07:05:36 PM
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
Title: Re: What is the proper way?
Post by: ober on July 17, 2008, 08:12:42 PM
http://www.phpclasses.org/browse/package/3156.html - there are a million classes out there that do this for you.  Just do a search.
Title: Re: What is the proper way?
Post by: Steve on July 17, 2008, 08:23:20 PM
fukin a. this must be one of those "didnt quite get it right on google" cases cuz i was searching all damn day. Thnx
Title: Re: What is the proper way?
Post by: Steve on July 18, 2008, 11:36:42 AM
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.
Title: Re: What is the proper way?
Post by: webwhy on July 18, 2008, 12:43:13 PM
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...
Title: Re: What is the proper way?
Post by: Steve on July 18, 2008, 01:13:18 PM
deleted
Title: Re: What is the proper way?
Post by: Steve on July 18, 2008, 01:17:17 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 18, 2008, 05:05:47 PM
deleted
Title: Re: What is the proper way?
Post by: Steve on July 18, 2008, 05:22:59 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 19, 2008, 02:39:54 PM
deleted
Title: Re: What is the proper way?
Post by: Steve on July 20, 2008, 01:31:46 PM
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 >_<
Title: Re: What is the proper way?
Post by: Steve on July 20, 2008, 05:16:21 PM
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.

Code: [Select]
$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.

Code: [Select]
<?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;
}

?>
Title: Re: What is the proper way?
Post by: Steve on July 20, 2008, 05:20:48 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 21, 2008, 05:26:52 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 21, 2008, 05:38:53 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 22, 2008, 06:29:56 PM
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.

Code: [Select]
$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;
Title: Re: What is the proper way?
Post by: Perspective on July 23, 2008, 11:31:46 AM
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
Title: Re: What is the proper way?
Post by: Mike on July 23, 2008, 11:33:48 AM
I bet he has a table called zip which has a column called zip.  Bad bad bad
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 12:00:09 PM
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";

Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 12:55:53 PM
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
Title: Re: What is the proper way?
Post by: ober on July 23, 2008, 01:03:33 PM
How are you pulling those variables out?
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 01:17:15 PM
In the query. Unless im confusing the use of "AS" which wouldnt suprise me
Title: Re: What is the proper way?
Post by: Mike on July 23, 2008, 01:31:26 PM
Well from your snippet of code you aren't doing the query nor are you fetching the results.
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 01:38:03 PM
somehow in my copy and paste i missed code. Dont ask how, we'll never figure me out:

Code: [Select]
<?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;
}

?>
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 02:24:53 PM
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
Title: Re: What is the proper way?
Post by: Perspective on July 23, 2008, 02:53:53 PM
>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).
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 02:55:32 PM
Okie can do, thanks
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 03:02:46 PM
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....
Title: Re: What is the proper way?
Post by: Mike on July 23, 2008, 03:09:11 PM
Code: [Select]
<?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?
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 03:12:11 PM
i thought i was assigning it in the AS statement. Now thats gone its

Code: [Select]
while ($ziprow = mysql_fetch_assoc($zipresult))
{
$latitude = $row['lat'];
$longitude = $row['lng'];
echo $latitude;
echo $longitude; }
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 03:42:50 PM
Think i got it, brb
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 03:51:12 PM
ok its working sorta i think im good now. THINK lol
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 05:04:39 PM
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.

Code: [Select]
$query = "SELECT * FROM asa_eventregister WHERE lat <= $lat1 AND lat >= $lat2 AND lng <= $long1 AND lng >= $long2";
Code: [Select]
<?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;
}

?>
Title: Re: What is the proper way?
Post by: Perspective on July 23, 2008, 07:42:20 PM
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?
Title: Re: What is the proper way?
Post by: Steve on July 23, 2008, 07:46:08 PM
No errors its just not echoing the rows in the final while statement. And yes the DB contains data and contains matches.
Title: Re: What is the proper way?
Post by: Steve on July 24, 2008, 09:43:34 AM
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.
Title: Re: What is the proper way?
Post by: Steve on July 24, 2008, 02:43:49 PM
How is it that both delta variable compute correctly, but then the long and lat computations all match.....wth

Code: [Select]
$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);
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:34:05 PM
I dont see an issue with $var = $var1 + $var2; but its not working correctly. The data is correct before the computation....wth
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 12:38:35 PM
Run this and paste the results please:
Code: [Select]
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>';
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:46:12 PM
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)
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:47:01 PM
String (13) + (13) are correct values.
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 12:47:07 PM
Do you see the problem yet?
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:49:18 PM
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?
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 12:52:29 PM
No, strings are fine but look at the value closely and compare them to the outputs of the floats
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:55:33 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 12:56:09 PM
well...theres 4's in there too.
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 01:02:36 PM
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"
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:07:51 PM
Im not getting it. The "10" is the radius given, and the two strings are the correct lat and long from the DB.
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:08:33 PM
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)
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 01:12:34 PM
/me pulls out the clue bat

Here's a hint:  $radius is fine
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:18:28 PM
extra " "? im going to go get coffee i think i need it
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 01:23:06 PM
there we go
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:31:39 PM
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?
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:35:08 PM
Ok it works now. Thanks mikey, now i gotta fix the whole DB.
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 01:35:29 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 01:41:21 PM
Ok i'll look into it
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 02:34:45 PM
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.
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 02:40:55 PM
What I would do is something like (important note:  I'm going to assume that the primary index is only one column called ind)
Code: [Select]
<?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!
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 02:47:36 PM
so can i set the zip col to primary and repleace ind with zip? Thnx appreciate it
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 02:55:28 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 03:03:27 PM
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

Code: [Select]
<?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);
?>
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 03:10:05 PM
hmm try this for the loop (as a test)
Code: [Select]
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.
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 03:13:18 PM
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"
}
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 03:19:28 PM
ok change the 2 in the substr to a 3 and use this in place of the query in the loop
Code: [Select]
$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 />';
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 03:28:14 PM
i musta messed up

Code: [Select]
<?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);
?>

Quote
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
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 03:37:35 PM
DOH!  That is my bad

in the query in the loop change $result to $result2
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 03:39:06 PM
i thought that was odd but what do i know LOL.
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 03:57:18 PM
After about 20min it changed all the "latitude" fields to "0" and thats it lol.
Title: Re: What is the proper way?
Post by: Mike on July 25, 2008, 05:15:17 PM
Well at least it is a valid number ;)

Shrug, I would probably just try a reimport making sure those two columns are properly formatted.
Title: Re: What is the proper way?
Post by: Steve on July 25, 2008, 05:59:03 PM
yea im going to screw it with it tomm. Appreciate all the help
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 12:58:55 PM
Eh i keep trying to get the php to work but i think im going to need to do it by hand
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 02:55:14 PM
i cant do this by hand i been here for 2 hours im not even out of the AL's yet
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 03:00:09 PM
Just out of curiousity i see

$arr = array();

but i dont even see it used?
Title: Re: What is the proper way?
Post by: Mike on July 26, 2008, 03:55:22 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 04:04:37 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 04:20:27 PM
Looking at php.org though i think it should be a "2" and not a "3"
Title: Re: What is the proper way?
Post by: Mike on July 26, 2008, 04:32:47 PM
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
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 04:41:00 PM
Sent, appreciate it.
Title: Re: What is the proper way?
Post by: Mike on July 26, 2008, 04:53:08 PM
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.
Title: Re: What is the proper way?
Post by: Mike on July 26, 2008, 04:53:38 PM
Oh and if you don't have a text editor that can do regular expressions get one that does.  It seriously helps A LOT
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 05:02:00 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 05:28:48 PM
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
Title: Re: What is the proper way?
Post by: Mike on July 26, 2008, 05:32:38 PM
I personally use editplus.  Worth the license fee IMO.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 05:38:35 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 05:56:10 PM
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.
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 09:32:02 PM
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.
Title: Re: What is the proper way?
Post by: ober on July 26, 2008, 11:35:51 PM
OMG... are you seriously still working on this thing?
Title: Re: What is the proper way?
Post by: Steve on July 26, 2008, 11:56:03 PM
Yea i know. It works, it just doesnt work right LOL. It doesnt make any goddamn sense.
Title: Re: What is the proper way?
Post by: Steve on July 27, 2008, 11:40:20 AM
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
Title: Re: What is the proper way?
Post by: Steve on July 27, 2008, 11:56:50 AM
It's the fucking math. I need a slop factor.
Title: Re: What is the proper way?
Post by: Steve on July 27, 2008, 12:03:07 PM
Got it, thank fucking god.