Quantcast

Forums | MacLife

You are not logged in.

#1 2006-03-26 12:47 am

ivanjs
Member
From: Ohio, USA
Registered: 2004-02-26
Posts: 219
Website

Dreamweaver dynamic links to sort columns?

I have a standard table display from a MySQL database, using Dreamweaver's great dynamic tools. What I'd also like to do is make the column headers a link, so when you click the column header link, it reorders the data based on the column you clicked. So if I had these columns:

Class   Instructor   Department

and initially, the whole table is sorted by Class, I want to be able to click Instructor and the page would reload with the data now sorted by Instructor.

Does anyone know how to make a link reorder a table ? I know how to do all the stuff like create a recordset, and I'm pretty strong with MySQL, I just can't seem to turn a link into a dynamic link that re-sorts the data.
Thanks
JOhn

Offline

 

#2 2006-03-27 5:06 am

W2ttsy
Member
Registered: 2002-03-04
Posts: 3294

Re: Dreamweaver dynamic links to sort columns?

well, in order to create the dynamic pages, youd be using PHP.

my tip, something that ive used before is to use a function and $_GET variable.

what youd want to do is to have a variable that uses the url as a way to push to a way to order the list.

use the following SQL

Code:

"SELECT * FROM tableName ORDER BY $tableName"

then what you want to do in your page is have a variable in the URL that is parsed to the SQL statement.

for instance

Code:

$tableName = $_GET["tableName"];

then have your URLs for each of the links

./pagename.php?tableName=class
./pagename.php?tableName=instructor
./pagename.php?tableName=department

now, when the link is clicked, the page is reloaded with the variable in the URL and that variable is then parsed to the SQL statement.
it is important to remember that the values of tableName in the URL must match the names of each of the columns in your database table.

hope this helps.

W2ttsy


http://img5.photobucket.com/albums/v15/collateral187/Misc/evil-fingers2.gif punk! http://members.cox.net/registered_user/maxes/big/rockon.gif

modding is for rich smurfs, hacking is for pov asses like me

Offline

 

#3 2006-03-28 12:10 am

jb
Member
From: Melbourne, Australia.
Registered: 2004-01-04
Posts: 2179

Re: Dreamweaver dynamic links to sort columns?

W2ttsy wrote:

well, in order to create the dynamic pages, youd be using PHP.

my tip, something that ive used before is to use a function and $_GET variable.

what youd want to do is to have a variable that uses the url as a way to push to a way to order the list.

use the following SQL

Code:

"SELECT * FROM tableName ORDER BY $tableName"

then what you want to do in your page is have a variable in the URL that is parsed to the SQL statement.

for instance

Code:

$tableName = $_GET["tableName"];

then have your URLs for each of the links

./pagename.php?tableName=class
./pagename.php?tableName=instructor
./pagename.php?tableName=department

now, when the link is clicked, the page is reloaded with the variable in the URL and that variable is then parsed to the SQL statement.
it is important to remember that the values of tableName in the URL must match the names of each of the columns in your database table.

hope this helps.

W2ttsy

./pagename.php?tableName=class;INSERT into `admins` ("username", "password", "notes") VALUES ("new_admin", "my_new_password", "Note: I h4x0red you");

Last edited by jb (2006-03-28 12:13 am)


They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.

Offline

 

#4 2006-03-28 6:24 am

Alien
Forum Czar
Administrator
From: Republic of Amsterdam
Registered: 1999-07-05
Posts: 16947
Website

Re: Dreamweaver dynamic links to sort columns?

lol

,xtG
.tsooJ


http://macstack.net/forums/images/smilies/lol.gif

Offline

 

#5 2006-03-29 4:02 am

W2ttsy
Member
Registered: 2002-03-04
Posts: 3294

Re: Dreamweaver dynamic links to sort columns?

"jb wrote:

words...

thanks for turning my nice easy example a lesson in security.

obviously he could guard against an injection attack by parsing the variable thru a filter or similar, but its a bit out of the scope...

W2ttsy


http://img5.photobucket.com/albums/v15/collateral187/Misc/evil-fingers2.gif punk! http://members.cox.net/registered_user/maxes/big/rockon.gif

modding is for rich smurfs, hacking is for pov asses like me

Offline

 

#6 2006-03-29 4:07 am

jb
Member
From: Melbourne, Australia.
Registered: 2004-01-04
Posts: 2179

Re: Dreamweaver dynamic links to sort columns?

Yeah, I know, I just didn't want him to go away with the idea that he was invincible, or something.
Nothing personal, at all. Sorry.


They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.

Offline

 

#7 2006-03-29 10:00 am

Alien
Forum Czar
Administrator
From: Republic of Amsterdam
Registered: 1999-07-05
Posts: 16947
Website

Re: Dreamweaver dynamic links to sort columns?

Don't use $tableName for a variable that holds a column name. Use $columnName.

,xtG
.tsooJ


http://macstack.net/forums/images/smilies/lol.gif

Offline

 

#8 2006-03-29 1:44 pm

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Dreamweaver dynamic links to sort columns?

jb wrote:

W2ttsy wrote:

well, in order to create the dynamic pages, youd be using PHP.

my tip, something that ive used before is to use a function and $_GET variable.

what youd want to do is to have a variable that uses the url as a way to push to a way to order the list.

use the following SQL

Code:

"SELECT * FROM tableName ORDER BY $tableName"

then what you want to do in your page is have a variable in the URL that is parsed to the SQL statement.

for instance

Code:

$tableName = $_GET["tableName"];

then have your URLs for each of the links

./pagename.php?tableName=class
./pagename.php?tableName=instructor
./pagename.php?tableName=department

now, when the link is clicked, the page is reloaded with the variable in the URL and that variable is then parsed to the SQL statement.
it is important to remember that the values of tableName in the URL must match the names of each of the columns in your database table.

hope this helps.

W2ttsy

./pagename.php?tableName=class;INSERT into `admins` ("username", "password", "notes") VALUES ("new_admin", "my_new_password", "Note: I h4x0red you");

You rock!


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#9 2006-03-29 1:52 pm

jb
Member
From: Melbourne, Australia.
Registered: 2004-01-04
Posts: 2179

Re: Dreamweaver dynamic links to sort columns?

Why? confused


They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.

Offline

 

#10 2006-03-29 3:13 pm

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Dreamweaver dynamic links to sort columns?

Because you are sooo l33t!

I am just glad someone else pointed out the dangers of passing data directly in to query before I did.


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#11 2006-03-29 10:46 pm

W2ttsy
Member
Registered: 2002-03-04
Posts: 3294

Re: Dreamweaver dynamic links to sort columns?

it was posted late at night. yes there were security flaws or something similar, but the ideas were there...

W2ttsy


http://img5.photobucket.com/albums/v15/collateral187/Misc/evil-fingers2.gif punk! http://members.cox.net/registered_user/maxes/big/rockon.gif

modding is for rich smurfs, hacking is for pov asses like me

Offline

 

#12 2006-03-30 3:40 am

jb
Member
From: Melbourne, Australia.
Registered: 2004-01-04
Posts: 2179

Re: Dreamweaver dynamic links to sort columns?

W2ttsy - relax. It wasn't anything personal, and your post was very helpful.


They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson