TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-30-2009, 02:07 PM   #1 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 13
Thanks: 0
trmbne2000 is on a distinguished road
Default Problem executing MSSQL query in PHP

Hello, I'm trying to run the following query against an MSSQL database in php:

PHP Code:
SELECT Lat,Lng FROM zip_lookup WHERE LOWER(ZIP) = 'k1a 0b1' 
zip_lookup is a table with latitude an longitude stored in numeric format, and zip codes stored in varchar(7); holding both US and canadian zip codes. It is used to calculate the distance between two zip codes for a radius search. With American ZIP codes, it works fine. However when I put in a Canadian postal code like the one above, no rows are returned when I run the query in PHP. However if I run the same query in SQL Server manager, I get:

Lat Lng
45.4100 -75.7000

Here is the code I'm using:

PHP Code:
function zipCoord($zip) {
    
$zip trim(strtolower($zip));
    
$zipSQL "SELECT Lat,Lng FROM zip_lookup WHERE LOWER(ZIP) = '{$zip}'";
    
$query mssql_query($zipSQL);
    if (!
$query) { die('MSSQL error: ' mssql_get_last_message()); }
    if (
$query && mssql_num_rows($query) > 0) {
        
$row mssql_fetch_array($query);
        
$result[] = $row[0];
        
$result[] = $row[1];
        return 
$result;
    } else {
        return 
false;
    }
}
...
$zipCoords zipCoord('K1A 0B1'); 
I have used echo $zipSQL to ensure that the correct SQL is executing, not errors are given and $query evaluates to true, which (according to manual) means that the query was successful.
Does anyone have any ideas what could be going on here?

Thanks,
Andrew
trmbne2000 is offline  
Reply With Quote
Old 06-30-2009, 02:44 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

var_dump for more info..
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-30-2009, 03:52 PM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 13
Thanks: 0
trmbne2000 is on a distinguished road
Default

OK, I actually ended up fixing up the problem by experimenting. This SQL solved it:

SELECT Lat,Lng FROM zip_lookup WHERE LOWER(ZIP) = 'k1a 0b1' AND ID > 0

Anyone know of any reasons why this would happen?

Thanks,
Andrew
trmbne2000 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search query multiple tables? (PHP, MySQL) shoaibmunir General 6 06-16-2009 02:47 PM
10 PHP Myths Dispelled Wildhoney General 10 06-15-2009 07:55 AM
Problem with Query + While $a = mysql_fetch_array($b) Aaron Absolute Beginners 0 07-03-2008 08:16 PM
Problem with Prototype and PHP wiifanatic Javascript, AJAX, E4X 3 02-18-2008 01:39 AM
php within a query CoryMathews Absolute Beginners 4 12-07-2007 03:20 PM


All times are GMT. The time now is 02:55 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design