473,326 Members | 2,182 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,326 software developers and data experts.

How can i display sort by ascending & descending list on PHP page from MySQL database

Hello My Dears,

I have php page with mySQL database. Here data is not sorted. Table is 4 column like as --
(1) Name
(2) Language
(3) Location
(4) Category

I want to display sorted by name (default option - an option that is selected automatically unless an alternative is specified. )

But visitors can display this list --

1. Sort by Name,
2. Sort by Language,
3. Sort by Location Or
4. Sort by Category

by click on table header option...

If anybody of my-dears can help me. Plz ....Plz ...... post Code 4 it.

Thanks
Apr 13 '12 #1
5 10954
johny10151981
1,059 1GB
i read your post and lost interest to answer.

but I will tell you this:

if you send a parameter to webserver such as sortby=Name

then in your php you can create a query like below:
"Select * FROM `desired_table` ORDER BY `".$received_data."`";
Apr 13 '12 #2
by core php ===>

<a href="view_details.php?by=name">Sort By Name</a>
<a href="view_details.php?by=language">Sort By Language</a>
<a href="view_details.php?by=location">Sort By Location</a>
<a href="view_details.php?by=category">Sort By Category</a>

on page ====>

<?php
if(isset($_GET['by']))
{
$search_by = $_GET['by'];

$qry = "select * from table_name order by ".$search_by.";
}
else
{
$qry = "select * from table_name";
}

$query = mysql_query($qry) or die(mysql_error());

while($row = mysql_fetch_array($query))
{
/* your displaying code here */

}

?>


Bharat Parmar(Bharat383)
Apr 14 '12 #3
if you wanna quick result then use AJAX on click calla javascript function and pass value in php page and fetch the result .....
it too speedy than core php and your whole page will not refresh just the details part will be fresh it's look more dynamic....
Apr 14 '12 #4
Thank you

Boss ...
Apr 15 '12 #5
The concept as follows as
Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['sorting']))
  2. {
  3.   if($_GET['sorting']=='ASC')
  4.   {
  5.   $sort='DESC';
  6.   }
  7.   else { $sort='ASC'; }
  8. }
visit: http://www.phponwebsites.com/2014/05...mn-header.html
May 8 '14 #6

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

Similar topics

2
by: Robert | last post by:
I need some help with formatting some text received from a database query. I am only selecting a single row per query so the formatting will only be performed on a single row. The rows I need to...
1
by: Seansan | last post by:
Hi there, I am trying to sort an array hash on values. I pass a FORM tag and resolve it to the array position to sort on. (see code below). Is there an easy way to sort ascending or descending...
1
by: pizzy | last post by:
Problem: I am trying to develope my personal site to select from my mysql database and organize data on the page so that it will display all the submissions for that day, then break and display...
2
by: Steve Chatham | last post by:
How do you make a sort work in ascending & descending order on the column in a datagrid. I have it now where it'll return the numbers from lowest to highest. SC
7
by: mukeshpatil | last post by:
How to get data from .CSV file using php & store it into Mysql database I want to read data from two different .CSV files using php & How to store it into Mysql Database tables Please help me...
0
by: Valandir | last post by:
I want to create a recordset navigator in order to "pass through" my records which are going to be shown to browser through a template. My database is Mysql and I am using Java scriptlets into my JSP...
6
blyxx86
by: blyxx86 | last post by:
I've created a form with a list box, above the list box are a few simple buttons. I'm trying to make them function as 'sort' buttons like in Windows Explorer. Where when you click on them they...
3
by: subho2009 | last post by:
Hello friends, I have face a problem, the problem is that when i fetch data from mysql database i get '&' in the place of '&amp;'. I am using php 5.1.2 and mysql version 5.0.11-beta. What is the...
2
by: mfaisalwarraich | last post by:
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...
1
by: gorgeousconcepts1 | last post by:
I am very new to PHP and am looking for some help with a problem that I am facing. I currently have a form which post to a table in MySQL. At the moment all the fields (apart from date) have to...
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...
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...
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...
1
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.