10-11-2011, 01:36 PM
|
#2 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
I don't think that MySQL has a function for string sorting, but php does, so you can do a retrieving query, then sort the string, then make an update query. For a simple example (and not tested or strong in security):
php Code:
$sql= "SELECT tblpartnumber, tblpartmanuf FROM tblparts WHERE tblpartnumber ='$frmpartfinder'"; $result = mysql_query($sql) or die('Error: ' . mysql_error()); $values = array(); while ($row = mysql_fetch_assoc($result)) { $sorted = usort(array($row[ 'tblpartmanuf'] ), "strcmp"); $values[ $row[ 'tblpartnumber']] = $sorted[ 0]; }foreach($values as $key => $val) { //assuming tblpartnumber is numeric mysql_query("UPDATE tblparts SET tblpartmanuf = '$val' WHERE tblpartnumber tblpartnumber"); }
This is a quick example and again not very good for production since it doesn't take into account query performance and security. But an example of using array sorting for string sorting by using usort
|
|
|
|