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 10-10-2011, 05:22 PM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 13
Thanks: 0
pepelepew1962 is on a distinguished road
Default sort the contents for a record field ...

Hello:

When I call up a specific record, I need to sort the contents of "tblpartmanuf" and replace that field with the sorted information. Lets say the record is:

tblpartnumber tblpartmanuf
12544 GFSD

After I edit some other fields, automatically sort the tblpartmanuf field so that it is:
12544 DFGS




$sql="SELECT tblpartnumber, tblpartmanuf FROM tblparts WHERE tblpartnumber ='$frmpartfinder'";
$result = mysql_query($sql) or die('Error: ' . mysql_error());
pepelepew1962 is offline  
Reply With Quote
Old 10-11-2011, 01:36 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

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
tony 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
Checkboxes working with text field Tim Dobson Absolute Beginners 1 10-02-2010 02:49 AM
Can't make it to sort... Peuplarchie Advanced PHP Programming 2 06-10-2009 12:23 PM
php/html form to echo text file contents Hustle Absolute Beginners 2 03-10-2009 07:14 AM
writing field data into the url? sarmenhb Absolute Beginners 4 09-26-2008 03:01 AM
Refresh an input field delayedinsanity Javascript, AJAX, E4X 5 07-27-2008 07:48 AM


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

 
     

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