Sorting alpha number query results
-
I have this query and I want the files to be displayed in order. The problem is they are Alpha numeric. I have tried sorting them also and nothing seems to work. Sometimes a few files that should be at the top are at the bottom. Notice some have spaces also. The files follow this format.
ABC123AB.gif
ABC123AB.jpg
DCG567CD.gif
DCG567CD.jpg
FG LMN WST.gif
FG LMN WST.gifglobal $wpdb; $out = ""; $query = "SELECT * FROM files WHERE prod_id = '". $this->curProduct ."' ORDER BY file_name ASC"; $files = $wpdb->get_results($query, ARRAY_A); if(count($files) >0) { $out .= "<h2>Title Here</h2>"; $out .= "<table id='xxx'>\n"; $row = 0; foreach($files as $file) { if($row % 2 == 1) $out .= '<tr>'; else $out .= '<tr class="even">'; $out .= '<td width="50"><a href="...../media/'. trim($file['file_name']) .'" target="_blank"><img src="/_image.png" alt="icon" /></a></td>'; $out .= '<td>'. $file['file_name'] . '</td>'; $out .= '</tr>'; $row++; } $out .= "</table>"; } return $out; }
The topic ‘Sorting alpha number query results’ is closed to new replies.