[PHP-DB] PHP and Mysql help
Can someone help me out with an issue I'm having? Here is my code: $res = mysql_query(SELECT ZG_LATITUDE, ZG_LONGITUDE FROM zip_code wherezg_zipcode = '$zip'); List($Lat,$Lon) = mysql_fetch_row($res); $Lat1 = ($Lat-2); $Lat2= ($Lat+2); $Lon1= ($Lon-2); $Lon2= ($Lon+2); //echo ($Lat1); //echo ($Lat2); //echo ($Lon1); //echo ($Lon2); $zipcode = mysql_query( SELECT * FROM zip_code where ZG_LATITUDE = $Lat1 and ZG_LATITUDE = $Lat2 and ZG_LONGITUDE = $Lon1 and ZG_LONGITUDE = $Lon2); if (!$zipcode) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($zipcode) ) { echo(bCity: /b . $row[ZG_CITY]. br); echo(bState: /b . $row[ZG_STATE]. br); echo(bZip Code: /b . $row[ZG_ZIPCODE]. br); echo(bArea Code: /b . $row[ZG_AREACODE]. br); echo(bCounty FIPS: /b . $row[ZG_COUNTY_FIPS]. br); echo(bCounty Name: /b . $row[ZG_COUNTY_NAME]. br); echo(bTime Zone: /b . $row[ZG_TIME_ZONE]. br); echo(bDay Light Savings?: /b . $row[ZG_DST]. br); echo(bLatitude: /b . $row[ZG_LATITUDE]. br); echo(bLongitude: /b . $row[ZG_LONGITUDE]. P); } I get no results with this still, it acutally doesn't even go to the this page. When I uncomment out: //echo ($Lat1); //echo ($Lat2); //echo ($Lon1); //echo ($Lon2); and comment out everything below this, I get the expected results for $Lat1,$Lat2,$Lon1, and $Lon2. So I have to believe my issue is below those lines, can anyone see what I have that is incorrect here?
Re: [PHP-DB] PHP and Mysql help
Hey, That is a lot of code, so I only skimmed it, but right off the bat i noticed that you are missing a space in between WHERE and zg_zipcode, as shown below: $res = mysql_query(SELECT ZG_LATITUDE, ZG_LONGITUDE FROM zip_code wherezg_zipcode = '$zip'); should be: $res = mysql_query(SELECT ZG_LATITUDE, ZG_LONGITUDE FROM zip_code WHERE zg_zipcode = '$zip'); I hope this helps... - Colin Busby --- Colin Busby Sackville, NB Canada http://www.colinbusby.ca On 24-Apr-05, at 7:54 PM, ReClMaples wrote: Can someone help me out with an issue I'm having? Here is my code: $res = mysql_query(SELECT ZG_LATITUDE, ZG_LONGITUDE FROM zip_code wherezg_zipcode = '$zip'); List($Lat,$Lon) = mysql_fetch_row($res); $Lat1 = ($Lat-2); $Lat2= ($Lat+2); $Lon1= ($Lon-2); $Lon2= ($Lon+2); //echo ($Lat1); //echo ($Lat2); //echo ($Lon1); //echo ($Lon2); $zipcode = mysql_query( SELECT * FROM zip_code where ZG_LATITUDE = $Lat1 and ZG_LATITUDE = $Lat2 and ZG_LONGITUDE = $Lon1 and ZG_LONGITUDE = $Lon2); if (!$zipcode) { echo(PError performing query: . mysql_error() . /P); exit(); } while ( $row = mysql_fetch_array($zipcode) ) { echo(bCity: /b . $row[ZG_CITY]. br); echo(bState: /b . $row[ZG_STATE]. br); echo(bZip Code: /b . $row[ZG_ZIPCODE]. br); echo(bArea Code: /b . $row[ZG_AREACODE]. br); echo(bCounty FIPS: /b . $row[ZG_COUNTY_FIPS]. br); echo(bCounty Name: /b . $row[ZG_COUNTY_NAME]. br); echo(bTime Zone: /b . $row[ZG_TIME_ZONE]. br); echo(bDay Light Savings?: /b . $row[ZG_DST]. br); echo(bLatitude: /b . $row[ZG_LATITUDE]. br); echo(bLongitude: /b . $row[ZG_LONGITUDE]. P); } I get no results with this still, it acutally doesn't even go to the this page. When I uncomment out: //echo ($Lat1); //echo ($Lat2); //echo ($Lon1); //echo ($Lon2); and comment out everything below this, I get the expected results for $Lat1,$Lat2,$Lon1, and $Lon2. So I have to believe my issue is below those lines, can anyone see what I have that is incorrect here?
Re: [PHP-DB] PHP and Mysql help
ReClMaples wrote: $zipcode = mysql_query( SELECT * FROM zip_code where ZG_LATITUDE = $Lat1 and ZG_LATITUDE = $Lat2 and ZG_LONGITUDE = $Lon1 and ZG_LONGITUDE = $Lon2); Try putting single quotes around the variables in your query string; mysql sees them as strings, not variables: ... ZG_LATITUDE = '$Lat1' and ZG_LATITUDE = '$Lat2' ... -Amos -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] PHP and mySQL help!
It looks like the problems is because $date and $host are in different form tags. So if one is set, then the other won't be. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Dzung Nguyen [mailto:[EMAIL PROTECTED]] Sent: Friday, January 10, 2003 1:33 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] PHP and mySQL help! Thanks for the quick reply! Perhaps I should describe my problem more specifically so that u could have a better idea: The code on PHP page to create forms for users to input field names: $tempdate = $date ; $tempselect = $select ; echo font size=$fontsize-1Choose datebr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\date\ value=\$tempdate\ size=17 maxlength=10/form ; echo /table ; $temphost = $host; echo font size=$fontsize-1Choose hostbr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\host\ value=\$temphost\ size=17 maxlength=10/form ; echo /table ; I then would concat the values to query the database as follow: echo a href=\build_form.php?select=alldate=$datehost=$hostorder=$orderorde rt wo=$ordertwoway=$waywaytwo=$waytwo\ target=\_top\ My problem right now is that I can't seem to keep both values. If one value is update (host for example), the other value (date) is no longer set??? Thanks again for your help. -- Dzung V. Nguyen email: [EMAIL PROTECTED] Alpha Linux Group http://linux.iol.unh.edu/clp InterOperability Laboratory University of New Hampshire phone: (603) - 862 - 0401 Durham, NH 03824fax : (603) - 862 - 4181 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP and mySQL help!
Hi! I have a PHP page with a few text areas where users can enter different combination of fields to query a mySQL database. An example of a query would be like this: $query = SELECT build_ids.build_id, build_ids.username, build_ids.host, build_ids.configuration, build_ids.build, build_ids.target, build_tests.input, build_tests.output, build_tests.result, build_tests.test_name, build_tests.prms_id, build_ids.date FROM build_ids, build_tests WHERE build_ids.date like \$date%\ and build_ids.host like \$host\ and build_ids.build_id like build_tests.build_id; The query would work if I use mySQL from command line, w/o using the variable, but use the field names themselves. But wouldn't work when I try to use variable like above and set the variables from a PHP page. Anybody knows what's wrong w/ my code or could show me to some helpful resources? Please reply to this email as I am not a subscriber of this list. Thank you very much! I really appreciate your help! -- Dzung V. Nguyen email: [EMAIL PROTECTED] Alpha Linux Group http://linux.iol.unh.edu/clp InterOperability Laboratory University of New Hampshire phone: (603) - 862 - 0401 Durham, NH 03824fax : (603) - 862 - 4181 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] PHP and mySQL help!
Are you sure $date and $host have a value? Is register globals on or off? Echo your query to the screen before you execute it to make sure it's what you think it is. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Dzung Nguyen [mailto:[EMAIL PROTECTED]] Sent: Friday, January 10, 2003 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] PHP and mySQL help! Hi! I have a PHP page with a few text areas where users can enter different combination of fields to query a mySQL database. An example of a query would be like this: $query = SELECT build_ids.build_id, build_ids.username, build_ids.host, build_ids.configuration, build_ids.build, build_ids.target, build_tests.input, build_tests.output, build_tests.result, build_tests.test_name, build_tests.prms_id, build_ids.date FROM build_ids, build_tests WHERE build_ids.date like \$date%\ and build_ids.host like \$host\ and build_ids.build_id like build_tests.build_id; The query would work if I use mySQL from command line, w/o using the variable, but use the field names themselves. But wouldn't work when I try to use variable like above and set the variables from a PHP page. Anybody knows what's wrong w/ my code or could show me to some helpful resources? Please reply to this email as I am not a subscriber of this list. Thank you very much! I really appreciate your help! -- Dzung V. Nguyen email: [EMAIL PROTECTED] Alpha Linux Group http://linux.iol.unh.edu/clp InterOperability Laboratory University of New Hampshire phone: (603) - 862 - 0401 Durham, NH 03824fax : (603) - 862 - 4181 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP and mySQL help!
Thanks for the quick reply! Perhaps I should describe my problem more specifically so that u could have a better idea: The code on PHP page to create forms for users to input field names: $tempdate = $date ; $tempselect = $select ; echo font size=$fontsize-1Choose datebr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\date\ value=\$tempdate\ size=17 maxlength=10/form ; echo /table ; $temphost = $host; echo font size=$fontsize-1Choose hostbr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\host\ value=\$temphost\ size=17 maxlength=10/form ; echo /table ; I then would concat the values to query the database as follow: echo a href=\build_form.php?select=alldate=$datehost=$hostorder=$orderordertwo=$ordertwoway=$waywaytwo=$waytwo\ target=\_top\ My problem right now is that I can't seem to keep both values. If one value is update (host for example), the other value (date) is no longer set??? Thanks again for your help. -- Dzung V. Nguyen email: [EMAIL PROTECTED] Alpha Linux Group http://linux.iol.unh.edu/clp InterOperability Laboratory University of New Hampshire phone: (603) - 862 - 0401 Durham, NH 03824fax : (603) - 862 - 4181 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] PHP and mySQL help!
If you update $date and nothing else on the page, are any of the other values in the URL (HREF) set? You have two separate forms. $date is in one and $host is in the other. However, all of the other variables in your URL (HREF) are from the second form where $host is. My guess is that since you have information coming from two separate forms, only data from one of the forms is being submitted. I might be totally wrong though because I don't know what happens when you use two forms on the same page, let alone two forms without names. If my theory is right, you should be able to use one form to encompass all of the data and use two separate tables within the form to format the controls on the page. Hope this helps. -Original Message- From: Dzung Nguyen [mailto:[EMAIL PROTECTED]] Sent: Friday, January 10, 2003 1:33 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] PHP and mySQL help! Thanks for the quick reply! Perhaps I should describe my problem more specifically so that u could have a better idea: The code on PHP page to create forms for users to input field names: $tempdate = $date ; $tempselect = $select ; echo font size=$fontsize-1Choose datebr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\date\ value=\$tempdate\ size=17 maxlength=10/form ; echo /table ; $temphost = $host; echo font size=$fontsize-1Choose hostbr/font form action=\build_form.php\ target=\_top\ method=get input type=hidden name=\select\ value=\$tempselect\ input type=hidden name=\order\ value=\$order\ input type=hidden name=\ordertwo\ value=\$ordertwo\ input type=hidden name=\way\ value=\$way\ input type=hidden name=\waytwo\ value=\$waytwo\ input type=\text\ name=\host\ value=\$temphost\ size=17 maxlength=10/form ; echo /table ; I then would concat the values to query the database as follow: echo a href=\build_form.php?select=alldate=$datehost=$hostorder=$ orderordertwo=$ordertwoway=$waywaytwo=$waytwo\ target=\_top\ My problem right now is that I can't seem to keep both values. If one value is update (host for example), the other value (date) is no longer set??? Thanks again for your help. -- Dzung V. Nguyen email: [EMAIL PROTECTED] Alpha Linux Group http://linux.iol.unh.edu/clp InterOperability Laboratory University of New Hampshire phone: (603) - 862 - 0401 Durham, NH 03824fax : (603) - 862 - 4181 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php