473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sort data inside mysql database using php

194 100+
Hi Everybody,

I am using the following function to get the data from mysql database. i have entered appnum field as text filed in the database which has leading zeroes to this field like if number is 0001, 0010, 0101 (four figures). Now i got problem while sorting them as it is a string value and its giving error when im trying to convert it into integer using (int)$appnum its trimming the leading zeros. I want this field as the string field and want the leading zeroes as it is. please tell me. how i can sort it in ascending or descening orders (numeric) thanx.

Expand|Select|Wrap|Line Numbers
  1. function seatingOrder(){
  2.  
  3.     $result = $this->database->Query("select id, appnum, name from datFrom SORT BY appnum ASC");
  4.     echo '<table cellpadding="5" cellspacing="2"  align="center">';
  5.     while($rows = mysql_fetch_assoc($result)){
  6.  
  7.     //$app = $rows["appnum"];
  8.     //$app = (int)$app;
  9.  
  10. echo '<tr><td>'.$rows["appnum"].'</td><td>'.$rows["id"].'</td><td>'.$rows["name"].'</td></tr>';
  11.  
  12.     }
  13.  
  14. echo '</table>';
  15.  
  16.  
  17. }
Aug 10 '09 #1
2 3982
dlite922
1,584 Expert 1GB
ORDER BY fieldName+0

That will convert the sort field to number, but will not touch the field itself.



Dan
Aug 10 '09 #2
mfaisalwarraich
194 100+
Thanx Dan it worked. thanx alot
Aug 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
2
by: Ruby Tuesday | last post by:
Hi, may be some of you MySQL database guru can shed me some lite to do the following: I have rows of data in mysql as follow: CODES ===== HH-1 .... HH-1000
1
by: Aaron | last post by:
I've been using MySQL for several months and enjoyed great success when installing other people's scripts to databses I make using phpMyAdmin. My challenge is developing from scratch the...
12
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
11
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them...
3
by: asadikhan | last post by:
Hi, I am trying to use a datalist to edit data in a MySql database as follows. For now I just want to be able to get the changes to be made on the dataset. Here is my code: using System;...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
9
NawazAhmed
by: NawazAhmed | last post by:
Hi, I saw the same titled post but the answer given there is abt how to import data from an input file. I know this can be done once u can get data from database in ur application using java,.net...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.