473,372 Members | 811 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,372 software developers and data experts.

Display X Items per page with sort option?

Ok, lets say I have 1000 items in my database (mysql) and want to
display X items per page. I learned to do it by querying with the LIMIT
constrain (something like this
http://www.snipe.net/content/view/12/35/). The problem is I cant sort
using this algorithm (or maybe I just dont know how to do it). ORDER BY
didnt do the trick for me :(.
The only way I can think of is to pass all the item keys/names/anything
I want to sort into an array, sort them there then pass the array
between pages. But I really dont like this idea. I know there must be
better way to do this, anyone can help a newbie?

Thanks a bunch!!!!!

Sep 8 '05 #1
8 2050
you should be able to use ORDER BY
SELECT * FROM table ORDER BY name LIMIT 1, 10

by using ORDER BY like this you will be keeping your paging intact.

what criteria are you using to sort by ?

yellow1912 wrote:
Ok, lets say I have 1000 items in my database (mysql) and want to
display X items per page. I learned to do it by querying with the LIMIT
constrain (something like this
http://www.snipe.net/content/view/12/35/). The problem is I cant sort
using this algorithm (or maybe I just dont know how to do it). ORDER BY
didnt do the trick for me :(.
The only way I can think of is to pass all the item keys/names/anything
I want to sort into an array, sort them there then pass the array
between pages. But I really dont like this idea. I know there must be
better way to do this, anyone can help a newbie?

Thanks a bunch!!!!!

Sep 8 '05 #2
In article <11**********************@g49g2000cwa.googlegroups .com>,
"yellow1912" <ye********@yahoo.com> wrote:
Ok, lets say I have 1000 items in my database (mysql) and want to
display X items per page. I learned to do it by querying with the LIMIT
constrain (something like this
http://www.snipe.net/content/view/12/35/). The problem is I cant sort
using this algorithm (or maybe I just dont know how to do it). ORDER BY
didnt do the trick for me :(.
The only way I can think of is to pass all the item keys/names/anything
I want to sort into an array, sort them there then pass the array
between pages. But I really dont like this idea. I know there must be
better way to do this, anyone can help a newbie?


You should use "order by" for this and let MySQL do the trick. Can't say why it
failed, but any given query could look like this:

select * from table order by date limit 25

For page navigation:

<?
if (!$_GET["start"]) $_GET["start"] = 0;
if (!$_GET["order"]) $_GET["order"] = 'date';

$sql = "select * from table order by $_GET[order] limit $_GET[start],25";
?>
--
Sandman[.net]
Sep 8 '05 #3
Thanks a bunch!!!

But I ran into this:
For example I have a column "NAME" contains name:
Name 1
Name 2
.....
Name 99

If I ORDER BY NAME DESC I will get something like this:
Name 99
Name 98
......
Name 90
Name 8 //The problems is here
Name 89
Name 88
......

The problem, I believe, is because of the way mysql compares the
strings. Hence make this sort kinda weird! How can I fix this, any
walk-around?

Sep 8 '05 #4
yellow1912 wrote:
Thanks a bunch!!!

But I ran into this:
For example I have a column "NAME" contains name:
Name 1
Name 2
....
Name 99

If I ORDER BY NAME DESC I will get something like this:
Name 99
Name 98
.....
Name 90
Name 8 //The problems is here
Name 89
Name 88
.....

The problem, I believe, is because of the way mysql compares the
strings. Hence make this sort kinda weird! How can I fix this, any
walk-around?


add a 0 to the 8 so it shows 08 in the DB. That'll make it order them
right.
Sep 8 '05 #5

"yellow1912" <ye********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks a bunch!!!

But I ran into this:
For example I have a column "NAME" contains name:
Name 1
Name 2
....
Name 99

If I ORDER BY NAME DESC I will get something like this:
Name 99
Name 98
.....
Name 90
Name 8 //The problems is here
Name 89
Name 88
.....

The problem, I believe, is because of the way mysql compares the
strings. Hence make this sort kinda weird! How can I fix this, any
walk-around?


make sure your feild type is set to integer ?
Sep 8 '05 #6
Big thanks guys!
But what if the field must be string, and I cant really control what
user input?
They can input Item 1, or Item 01, .... There's no way ?

Sep 8 '05 #7
yellow1912 wrote:
Big thanks guys!
But what if the field must be string, and I cant really control what
user input?
They can input Item 1, or Item 01, .... There's no way ?

you can control what you put in the db though. There's a php function
that'll float the number to any given number of leading 0's.

I wrote some code that helps me move things around in my knowledge base
when incidents or articles are added.

$code = "FF00512"; // KB code, pulled from the end of the table
$prefix = substr($code,0,2); // output: "FF"
$suffix = substr($code,2,5)+1; // "00512" + 1, output: "513"
$suffix = sprintf("%05d", $suffix); // output: "00513"
$solutionid = $prefix.$suffix; // combine the prefix and the suffix

echo $solutionid; // output: "FF00513"

you could change the %05d to %03d, it'll make sure the integer is 3
numbers long and add leading zero's until it matches that. %05d will be
5 numbers, %07d 7 numbers and so on...

im sure there are easier ways to do this, but this was my solution.
Sep 8 '05 #8
Thanks everyone for your kind help and suggestion! I will surely try
all the solution suggested by you

Sep 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
5
by: hiroshi ochi | last post by:
Hello, Using MSIE 6.0 and above, with javascript is it possible to display an individual tooltip for each item in a listbox? I need this functionality to show the listitems that are longer...
4
by: Hardy Wang | last post by:
Hi I have a ListBox control in my ASP.NET page. After I binding data to this control, I would like to be able to change this display order of items in this control. Just like change layout...
2
by: martin | last post by:
Hi, I have a dropdown control tha is rendered with the follwoing HTML <select name="FirstStep:CmbTargetGroup" id="FirstStep_CmbTargetGroup" style="width:152px;"> <option...
1
by: Henrik | last post by:
Hello all. I'm after some sort of pagination function. One that takes some in data that I provide, and returns an array of controls, pointing to page 2, page 3 etc. Trying to mimic the way that...
0
by: Zaphod | last post by:
greetings! My question is this; I have a rss news feed up and running on a website, but I would like to sift through the 30-40 items provided and display only the ones with a certian word in the...
2
by: HarisHohkl | last post by:
Hi, I've this function in a class to update the total value.but when i try to remove the these row highlight in Bold it crash, what should i do???? void display_total_value() { double...
1
by: fsalvador | last post by:
Hi, I need help with this. I am trying to figure it out but I can't. I have 2 pages. I would like to display in the second page the content of one class and hide the content of the other...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.