Jump to content

Query results order - coming out funky??


amites

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.