| ||||||||||||
| ||||||||||||
Code misses out when data has spaces Posted by Chris_Isaac (Chris Isaac), 23 July 2003 HiThe following code almost works correctly. It performs a search on a given town name and produces a list of matching towns and their countys. fine so far but it seems to be missing the counties if there are spaces in the town name, eg, Newport Pagnell then misses out Buckinghamshire. Also Newport, Isle of White is missed out completely. If I change the: array_push($county,$row[0]); line to array_push($county,$row[1]); It produces a list of counties fine, but no town names. I've also tried exploding the following line, but that didn't work: list($t,$c) = split(",",$current); Any ideas appreciated. Chris ![]() Code:
Posted by admin (Graham Ellis), 23 July 2003 Try doing a "view source" on the page that's returned to you; I suspect that you're generating HTML that includes space characters within an HREF parameter which you should replace with + characters (URL encoding!).Posted by Chris_Isaac (Chris Isaac), 24 July 2003 Sorry, the code wasn't quite doing what I thought it was, row[0] was only pulling in the town field, but it had Newport, Gwent down as the town which was confusing me.I've changed the script as per below, again I'm close, its printing all as it should, but it prints it out 3 times. I think the problem is in the loop, but a can't seem to keep the county field if I take/move the print statement from its current position. any hints please? Thanks Chris Code:
Posted by admin (Graham Ellis), 24 July 2003 You haven't by any chance loaded the towns file into your database three times have you ![]() Do you get each town coming out three times in sucession, or the whole list three times over? Posted by Chris_Isaac (Chris Isaac), 24 July 2003 No, I did do that, but then corrected it before trying these scripts ![]() Here is the output from the script if you search on the word newport: Town: Newport -- County : County Down Town: Newport -- County : Isle of Wight Town: Newport -- County : Gwent Town: Newport -- County : Buckinghamshire Town: Newport -- County : Pembrokeshire Town: Newport -- County : Shropshire Town: Newport -- County : County Down Town: Newport -- County : Isle of Wight Town: Newport -- County : Gwent Town: Newport -- County : Buckinghamshire Town: Newport -- County : Pembrokeshire Town: Newport -- County : Shropshire Town: Newport -- County : County Down Town: Newport -- County : Isle of Wight Town: Newport -- County : Gwent Town: Newport -- County : Buckinghamshire Town: Newport -- County : Pembrokeshire Town: Newport -- County : Shropshire Town: Newport Pagnell -- County : Buckinghamshire Town: Newport, Pembrokeshire -- County : Pembrokeshire Town: Newport, Shropshire -- County : Shropshire and here is the output if you do a select on the relevant table: +------+------------------------+------------------+---------+-----------+ | id | town | county | country | saycounty | +------+------------------------+------------------+---------+-----------+ | 1080 | Newport | County Down | UK | 1 | | 1090 | Newport | Isle of Wight | UK | 1 | | 1091 | Newport | Gwent | UK | 1 | | 1092 | Newport Pagnell | Buckinghamshire | UK | 1 | | 1095 | Newport, Pembrokeshire | Pembrokeshire | UK | 1 | | 1096 | Newport, Shropshire | Shropshire | UK | 1 | +------+------------------------+------------------+---------+-----------+ 6 rows in set (0.00 sec) Thanks Chris Posted by admin (Graham Ellis), 24 July 2003 OK - I think I spot it now. I think you're generating a list of all the "Newport" towns - six of them. For each of the towns you got, you are doing a query that looks for the town name again and pulls in the county. For "Newport", it gets six matches (and it does that three times), then for the three places that have longer names you're getting just one response.Sorry - Chris - I think your logic is more comples that it needs to be - I think you only need to do one query which looks for "Newport". If it gets just one row back that's great - you have a unique town; if it gets more than one row back, simply collect the town and country fields .... Posted by Chris_Isaac (Chris Isaac), 25 July 2003 the original script (please see below) produced a county list as per: Town: newport -- County : County Down Town: newport -- County : Isle of Wight Town: newport -- County : Gwent Town: newport -- County : Buckinghamshire Town: newport -- County : Pembrokeshire Town: newport -- County : Shropshire which is what I want. the problem is newport above is pulled from $town which in turn is basically what is entered in in the in the text box, this is fine so far, but if someone puts in a partial word, eg, new and does a search, and does pull all the correct counties, but doesn't pull the complete town name, so I get a list like: new, Gwent new, IOW blah blah..... how do I get the town name for each individual county listed? Thanks Chris Code:
Posted by admin (Graham Ellis), 25 July 2003 use $row[0] back from your SQL request as the town name in the subsequent report / pulldown menu, rather than the value entered by the user into the variable $town. Just as you push the counties onto an array, you can push the towns actually found onto an array ![]() Posted by Chris_Isaac (Chris Isaac), 25 July 2003 Just a quick note to say thanksI changed the array_push line to : Code:
and the loop to : Code:
and it works like a dream. Again thanks for the pointers... Chris This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| |||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |