amites Posted February 21, 2008 Share Posted February 21, 2008 Hello, I have a simple question, I have a query echo "<select name='locstate' onChange=\"dochange('cities', this.value)\" >" . "<option value='0'>".$txt_select_state."</option>\n"; $result=mysql_query("select `id`, `english` FROM " . $database_prefix . "states ORDER BY `english`"); while(list($id, $name)=mysql_fetch_array($result)){ echo "<option value=\"$id\" >$name</option>" ; } echo "</select>"; that is spitting out results that are alphabetical, though the first few lines show up at the end, for example: <select onchange="dochange('location', this.value)" name="loccity"><option value="0">Select a City:</option><option value="1031"> Brookside</option><option value="1032"> Claymont</option><option value="1033"> Dover</option><option value="1034"> Glasgow</option><option value="1035"> Hockessin</option><option value="1036"> Middletown</option><option value="1037"> Milford</option><option value="1038"> Newark</option><option value="1039"> North Star</option><option value="1040"> Pike Creek</option><option value="1041"> Seaford</option><option value="1042"> Wilmington</option><option value="1043"> Wilmington Manor</option><option value="1030">Bear</option></select> notice the last entry in the list? any ideas? in states with more cities in it I will get up to 8 or so of the first few rows showing up at the end in alphabetical order, so a, b, c, d, e, f, g would come out d, e, f, g, a, b, c this was working properly before and I don't remember changing anything, it just started running through this way, even after I reverted to an older copy of this script it's called by AJAX if that makes a difference any thoughts are greatly appreciated Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/ Share on other sites More sharing options...
rhodesa Posted February 21, 2008 Share Posted February 21, 2008 It looks like the values in the 'english' column of the table have a new line character in from of them (and Bear doesn't). Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-473064 Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 It looks like the values in the 'english' column of the table have a new line character in from of them (and Bear doesn't). That is brilliant. I was racking my brain looking at that one ??? Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-473070 Share on other sites More sharing options...
amites Posted February 26, 2008 Author Share Posted February 26, 2008 Many thanks, that was getting annoying, now i have a new one... any chance of getting some help building a query to remove the new lines? hate to do it manually, just been staring at a screen to long to think it out right now... Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-476506 Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 Do a backup of the data first, but this SQL command should do it: mysql_query("UPDATE " . $database_prefix . "states SET `english` = TRIM(`english`)"); TRIM is a mysql function that will remove leading and trailing whitespace just like PHP's trim function. Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-476521 Share on other sites More sharing options...
amites Posted February 26, 2008 Author Share Posted February 26, 2008 thanks for the update, I gave it a shot and it didn't give me any results, no errors though... thinking I'm going to work on this tomorrow 16 hours is my limit once again I appreciate the help Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-476717 Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 It won't return any results. It's an UPDATE which alters the data in the database. After the command, the values in there shouldn't have the new lines anymore. So just go back to your other script with does the SELECT, and see if those new line characters are still there. Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-476948 Share on other sites More sharing options...
amites Posted February 26, 2008 Author Share Posted February 26, 2008 I should have been more specific, checked on the results and the new lines were still there, after running the script, directly in mySQL and through PHP Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-477172 Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 Ah, just tested and the default is only space characters I guess. Just have to tell it to do new lines too: UPDATE states SET `english` = TRIM(LEADING '\n' FROM `english`) Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-477185 Share on other sites More sharing options...
amites Posted February 27, 2008 Author Share Posted February 27, 2008 still not doing it, thinking I might just dump the table and run it through dreamweaver, become a huge fan of the search and replace function in that program many thanks for the help so far Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-478488 Share on other sites More sharing options...
amites Posted February 27, 2008 Author Share Posted February 27, 2008 think I got it, when I dumped the table it came out: INSERT INTO bil_cities (`id`, `state_id`, `english`) VALUES (3, 1, '\r\nAlexander City'); I think that \r was throwing things off damn Windows Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-478493 Share on other sites More sharing options...
rhodesa Posted February 28, 2008 Share Posted February 28, 2008 ah...in that case, there is no leading \n cus a \r is in front of it...so: UPDATE states SET `english` = TRIM(LEADING '\r\n' FROM `english`) Link to comment https://forums.phpfreaks.com/topic/92331-query-results-order-coming-out-funky/#findComment-478760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.