[Besoin d'aide - PHP / MySQL] - cliquable / têtes de tableau triable
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Donc, j'ai suivi ce guide:
http://scriptplayground .com / tutorials / php / Impression-a-MySQL-table-à-une-dynamique-HTML-table-avec-PHP /
Et me faire une belle table cherche ma base de données. Maintenant, je veux que ce soit "sortable".
Comment ferais-je les en-têtes de colonne / titres "cliquables" afin que le tableau est ORDER BY qui colonne? De plus, jaimerais cliquez une deuxième fois pour changer l'ordre de monter à descendant, ou vice versa.
Exemple:
Une table qui comporte des colonnes: Nom, âge, poids
Le tableau des listes par "Nom", en descendant, par défaut. Lorsque je clique sur "Nom", les changements afin de descendre à ascendante. Lorsque je clique sur "Age", la table est re-classés par âge, descendant.
Des idées?
http://scriptplayground .com / tutorials / php / Impression-a-MySQL-table-à-une-dynamique-HTML-table-avec-PHP /
Et me faire une belle table cherche ma base de données. Maintenant, je veux que ce soit "sortable".
Comment ferais-je les en-têtes de colonne / titres "cliquables" afin que le tableau est ORDER BY qui colonne? De plus, jaimerais cliquez une deuxième fois pour changer l'ordre de monter à descendant, ou vice versa.
Exemple:
Une table qui comporte des colonnes: Nom, âge, poids
Le tableau des listes par "Nom", en descendant, par défaut. Lorsque je clique sur "Nom", les changements afin de descendre à ascendante. Lorsque je clique sur "Age", la table est re-classés par âge, descendant.
Des idées?
- Anonymous
- Bot


- Inscription: 25 Feb 2008
- Messages: ?
- Loc: Ozzuland
- Status: Online
Mars 6th, 2010, 7:00 pm
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Combien de temps faut-il pour obtenir des réponses sur ce forum? Je suis nouveau à OZZU, donc je ne sais pas grand-chose, mais les forums je participe habituellement seulement prendre une heure ou deux tout au plus à obtenir des réponses.... Its been 2 jours depuis que j'ai commencé ce sujet...Doesnt quelqu'un sait comment faire cela?
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Ill vous donner tout ce que j'ai 
Wii.php
SQLTables.php
<?php
function display_db_query($query_string, $connection, $image, $table_params) {
$result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
$column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// Print Headers
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH>$field_name</TH>");
}
print("</TR>\n");
// Print the body
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
if($column_num==0 && $image){
print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
}
else{
print("<TD>$row[$column_num]</TD>\n");
}
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($tablename, $sort, $connection, $image, $table_params) {
$query_string = "SELECT * FROM $tablename ORDER BY $sort";
display_db_query($query_string, $connection, $image, $table_params);
}
?>
Wii.php
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3 .org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nintendo Wii Game Lists</title>
</head>
<?php
include("./SQLTables.php");
?>
<body>
<div align="center">
<h1>Nintendo Wii Games Lists</h1>
</div>
<div align="center">
<h2>Wish List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "wish_list";
$sort = "Name";
display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
?></p>
<div align="center">
<h2>Owned List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "owned_list";
$sort = "Name";
display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
?></p>
</div>
</body>
</html>
<html xmlns="http://www.w3 .org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nintendo Wii Game Lists</title>
</head>
<?php
include("./SQLTables.php");
?>
<body>
<div align="center">
<h1>Nintendo Wii Games Lists</h1>
</div>
<div align="center">
<h2>Wish List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "wish_list";
$sort = "Name";
display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
?></p>
<div align="center">
<h2>Owned List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "owned_list";
$sort = "Name";
display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
?></p>
</div>
</body>
</html>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3 .org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Nintendo Wii Game Lists</title>
- </head>
- <?php
- include("./SQLTables.php");
- ?>
- <body>
- <div align="center">
- <h1>Nintendo Wii Games Lists</h1>
- </div>
- <div align="center">
- <h2>Wish List</h2>
- <p><?php
- //Connection
- $global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
- $database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
- $table = "wish_list";
- $sort = "Name";
- display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
- ?></p>
- <div align="center">
- <h2>Owned List</h2>
- <p><?php
- //Connection
- $global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
- $database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
- $table = "owned_list";
- $sort = "Name";
- display_db_table($table, $sort, $global_dbh, FALSE, "border='5'");
- ?></p>
- </div>
- </body>
- </html>
SQLTables.php
Code: [ Select ]
<?php
function display_db_query($query_string, $connection, $image, $table_params) {
$result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
$column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// Print Headers
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH>$field_name</TH>");
}
print("</TR>\n");
// Print the body
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
if($column_num==0 && $image){
print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
}
else{
print("<TD>$row[$column_num]</TD>\n");
}
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($tablename, $sort, $connection, $image, $table_params) {
$query_string = "SELECT * FROM $tablename ORDER BY $sort";
display_db_query($query_string, $connection, $image, $table_params);
}
?>
- <?php
- function display_db_query($query_string, $connection, $image, $table_params) {
- $result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
- $column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
- // Here the table attributes from the $table_params variable are added
- print("<TABLE $table_params >\n");
- // Print Headers
- print("<TR>");
- for($column_num = 0; $column_num < $column_count; $column_num++) {
- $field_name = mysql_field_name($result_id, $column_num);
- echo ("<TH>$field_name</TH>");
- }
- print("</TR>\n");
- // Print the body
- while($row = mysql_fetch_row($result_id)) {
- print("<TR ALIGN=LEFT VALIGN=TOP>");
- for($column_num = 0; $column_num < $column_count; $column_num++) {
- if($column_num==0 && $image){
- print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
- }
- else{
- print("<TD>$row[$column_num]</TD>\n");
- }
- }
- print("</TR>\n");
- }
- print("</TABLE>\n");
- }
- function display_db_table($tablename, $sort, $connection, $image, $table_params) {
- $query_string = "SELECT * FROM $tablename ORDER BY $sort";
- display_db_query($query_string, $connection, $image, $table_params);
- }
- ?>
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
Ce que vous faites est un peu compliquée, car complètement sa dynamique.
Fondamentalement, ce que votre départ pour savoir quoi faire est, pour chaque champ que vous voulez faire en son nom un lien et d'envoyer ce champ que vous voulez effectuer le tri et a joint la direction (asc, desc)
Votre $ sort changera selon whats actuellement définies.
Fondamentalement, ce que votre départ pour savoir quoi faire est, pour chaque champ que vous voulez faire en son nom un lien et d'envoyer ce champ que vous voulez effectuer le tri et a joint la direction (asc, desc)
Code: [ Select ]
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH><a href="page.php?order_by=$field_name&sorting=$sort</TH>");
}
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH><a href="page.php?order_by=$field_name&sorting=$sort</TH>");
}
- for($column_num = 0; $column_num < $column_count; $column_num++) {
- $field_name = mysql_field_name($result_id, $column_num);
- echo ("<TH><a href="page.php?order_by=$field_name&sorting=$sort</TH>");
- }
Votre $ sort changera selon whats actuellement définies.
Code: [ Select ]
$order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'Name';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
- $order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'Name';
- $sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
Code: [ Select ]
switch($sorting) {
case "asc":
$sort = 'desc';
break;
case "desc":
$sort = 'asc';
break;
}
case "asc":
$sort = 'desc';
break;
case "desc":
$sort = 'asc';
break;
}
- switch($sorting) {
- case "asc":
- $sort = 'desc';
- break;
- case "desc":
- $sort = 'asc';
- break;
- }
#define NULL (::rand() % 2)
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Sérieusement...MERCI!
Wii.php
SQLTables.php
Im un grand fan de code dynamique
Tout cela fonctionne très bien et bon, mais...J'ai 2 tableaux de la page et il est à la fois le rechargement de celles qui utilisent le «clic» d'une table. Donc, si je clique sur la colonne "Name" dans la liste de souhaits, tant la liste de souhaits et la liste de détenus sont en train de s'organiser par leur nom. Je peux presque vivre avec cela, mais si vous cliquez sur le «prix» de la colonne, la table appartenant à la liste disparaît parce que je ne dispose pas d'un "prix" dans la colonne owned_list "" table de la base, de sorte que l'on me donne une erreur.
Pas vraiment vraiment comment il peut se déplacer à celui-ci...Je veux seulement l'unique table pour obtenir rechargées lorsque l'on clique sur la rubrique liens...
Wii.php
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3 .org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nintendo Wii Game Lists</title>
</head>
<?php
include("./SQLTables.php");
?>
<body>
<div align="center">
<h1>Nintendo Wii Games Lists</h1>
</div>
<div align="center">
<h2>Wish List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "wish_list";
$page = "Wii";
display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
?></p>
<div align="center">
<h2>Owned List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "owned_list";
$page = "Wii";
display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
?></p>
</div>
</body>
</html>
<html xmlns="http://www.w3 .org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nintendo Wii Game Lists</title>
</head>
<?php
include("./SQLTables.php");
?>
<body>
<div align="center">
<h1>Nintendo Wii Games Lists</h1>
</div>
<div align="center">
<h2>Wish List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "wish_list";
$page = "Wii";
display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
?></p>
<div align="center">
<h2>Owned List</h2>
<p><?php
//Connection
$global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
$database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
$table = "owned_list";
$page = "Wii";
display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
?></p>
</div>
</body>
</html>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3 .org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Nintendo Wii Game Lists</title>
- </head>
- <?php
- include("./SQLTables.php");
- ?>
- <body>
- <div align="center">
- <h1>Nintendo Wii Games Lists</h1>
- </div>
- <div align="center">
- <h2>Wish List</h2>
- <p><?php
- //Connection
- $global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
- $database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
- $table = "wish_list";
- $page = "Wii";
- display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
- ?></p>
- <div align="center">
- <h2>Owned List</h2>
- <p><?php
- //Connection
- $global_dbh = mysql_connect('localhost','root','mangos') or die("Unable to connect: " . mysql_error() . "<br>");
- $database = mysql_select_db("wii game list") or die( "Unable to select database<br>");
- $table = "owned_list";
- $page = "Wii";
- display_db_table($page, $table, $global_dbh, FALSE, "border='5'");
- ?></p>
- </div>
- </body>
- </html>
SQLTables.php
Code: [ Select ]
<?php
function display_db_query($page, $query_string, $connection, $sort, $image, $table_params) {
$result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
$column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// Print Headers
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH><a href=\"$page.php?order_by=$field_name&sorting=$sort\">$field_name</a></TH>");
}
print("</TR>\n");
// Print the body
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
if($column_num==0 && $image){
print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
}
else{
print("<TD>$row[$column_num]</TD>\n");
}
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($page, $tablename, $connection, $image, $table_params) {
$order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'Name';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
switch($sorting){
case "asc":
$sort = 'desc';
break;
case "desc":
$sort = 'asc';
break;
}
$query_string = "SELECT * FROM $tablename ORDER BY $order_by"." $sort";
display_db_query($page, $query_string, $connection, $sort, $image, $table_params);
}
?>
function display_db_query($page, $query_string, $connection, $sort, $image, $table_params) {
$result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
$column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// Print Headers
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
echo ("<TH><a href=\"$page.php?order_by=$field_name&sorting=$sort\">$field_name</a></TH>");
}
print("</TR>\n");
// Print the body
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
if($column_num==0 && $image){
print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
}
else{
print("<TD>$row[$column_num]</TD>\n");
}
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($page, $tablename, $connection, $image, $table_params) {
$order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'Name';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
switch($sorting){
case "asc":
$sort = 'desc';
break;
case "desc":
$sort = 'asc';
break;
}
$query_string = "SELECT * FROM $tablename ORDER BY $order_by"." $sort";
display_db_query($page, $query_string, $connection, $sort, $image, $table_params);
}
?>
- <?php
- function display_db_query($page, $query_string, $connection, $sort, $image, $table_params) {
- $result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error());
- $column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error());
- // Here the table attributes from the $table_params variable are added
- print("<TABLE $table_params >\n");
- // Print Headers
- print("<TR>");
- for($column_num = 0; $column_num < $column_count; $column_num++) {
- $field_name = mysql_field_name($result_id, $column_num);
- echo ("<TH><a href=\"$page.php?order_by=$field_name&sorting=$sort\">$field_name</a></TH>");
- }
- print("</TR>\n");
- // Print the body
- while($row = mysql_fetch_row($result_id)) {
- print("<TR ALIGN=LEFT VALIGN=TOP>");
- for($column_num = 0; $column_num < $column_count; $column_num++) {
- if($column_num==0 && $image){
- print("<TD><img src=imageLoader.php?image=amf_bowling</TD>\n");
- }
- else{
- print("<TD>$row[$column_num]</TD>\n");
- }
- }
- print("</TR>\n");
- }
- print("</TABLE>\n");
- }
- function display_db_table($page, $tablename, $connection, $image, $table_params) {
- $order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'Name';
- $sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
- switch($sorting){
- case "asc":
- $sort = 'desc';
- break;
- case "desc":
- $sort = 'asc';
- break;
- }
- $query_string = "SELECT * FROM $tablename ORDER BY $order_by"." $sort";
- display_db_query($page, $query_string, $connection, $sort, $image, $table_params);
- }
- ?>
Im un grand fan de code dynamique
Tout cela fonctionne très bien et bon, mais...J'ai 2 tableaux de la page et il est à la fois le rechargement de celles qui utilisent le «clic» d'une table. Donc, si je clique sur la colonne "Name" dans la liste de souhaits, tant la liste de souhaits et la liste de détenus sont en train de s'organiser par leur nom. Je peux presque vivre avec cela, mais si vous cliquez sur le «prix» de la colonne, la table appartenant à la liste disparaît parce que je ne dispose pas d'un "prix" dans la colonne owned_list "" table de la base, de sorte que l'on me donne une erreur.
Pas vraiment vraiment comment il peut se déplacer à celui-ci...Je veux seulement l'unique table pour obtenir rechargées lorsque l'on clique sur la rubrique liens...
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
SpooF a écrit:
Vous pouvez utiliser le nom d'une autre variable dans l'url à différer de chaque table.
Ya, j'ai pensé que ça, mais .., wouldnt j'ai besoin de suivre tous les tableaux sur la page et assurez-vous que chacun est répertoriée par la dernière position qui a été cliqué? Id besoin pour être dynamique et extensible à% i nombre de tables sur une seule page...
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
Voici un exemple d'utiliser les sessions pour stocker vos données pour chaque table.
Cela nécessite que vos liens donner un nom de table, champ pour le tri et la façon dont vous voulez qu'il soit trié.
PHP Code: [ Select ]
<?
// begin the session
session_start();
$table_name = (isset($_GET['table'])) ? $_GET['table'] : NULL;
$order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'id';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
// Check to see if we have some data saved in our session
if(isset($_SESSION['table_info']))
{
// Get data in session
$table_info = $_SESSION['table_info'];
}
else
{
// There's no data in the session so lets initialize an array
$table_info = array();
}
// If there is no table supplied we can't do much
if($table_name != NULL)
{
// Check if the table already has data in our session
if(isset($table_info[$table_name]))
{
// Get table data from session
$table = $table_info[$table_name];
}
else
{
// There's no data for the table so lets initialize an array for the table
$table = array();
}
// Update table data (these should always be given in the url so we wont worry about not updating them if they are not set)
$table['order_by'] = $order_by;
$table['sorting'] = $sorting;
// Put the table back into our array
$table_info[$table_name] = $table;
}
// Update session with new data
$_SESSION['table_info'] = $table_info;
echo '<pre>';
print_r($table_info);
echo '</pre>';
?>
// begin the session
session_start();
$table_name = (isset($_GET['table'])) ? $_GET['table'] : NULL;
$order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'id';
$sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
// Check to see if we have some data saved in our session
if(isset($_SESSION['table_info']))
{
// Get data in session
$table_info = $_SESSION['table_info'];
}
else
{
// There's no data in the session so lets initialize an array
$table_info = array();
}
// If there is no table supplied we can't do much
if($table_name != NULL)
{
// Check if the table already has data in our session
if(isset($table_info[$table_name]))
{
// Get table data from session
$table = $table_info[$table_name];
}
else
{
// There's no data for the table so lets initialize an array for the table
$table = array();
}
// Update table data (these should always be given in the url so we wont worry about not updating them if they are not set)
$table['order_by'] = $order_by;
$table['sorting'] = $sorting;
// Put the table back into our array
$table_info[$table_name] = $table;
}
// Update session with new data
$_SESSION['table_info'] = $table_info;
echo '<pre>';
print_r($table_info);
echo '</pre>';
?>
- <?
- // begin the session
- session_start();
- $table_name = (isset($_GET['table'])) ? $_GET['table'] : NULL;
- $order_by = (isset($_GET['order_by'])) ? $_GET['order_by'] : 'id';
- $sorting = (isset($_GET['sorting'])) ? $_GET['sorting'] : 'desc';
- // Check to see if we have some data saved in our session
- if(isset($_SESSION['table_info']))
- {
- // Get data in session
- $table_info = $_SESSION['table_info'];
- }
- else
- {
- // There's no data in the session so lets initialize an array
- $table_info = array();
- }
- // If there is no table supplied we can't do much
- if($table_name != NULL)
- {
- // Check if the table already has data in our session
- if(isset($table_info[$table_name]))
- {
- // Get table data from session
- $table = $table_info[$table_name];
- }
- else
- {
- // There's no data for the table so lets initialize an array for the table
- $table = array();
- }
- // Update table data (these should always be given in the url so we wont worry about not updating them if they are not set)
- $table['order_by'] = $order_by;
- $table['sorting'] = $sorting;
- // Put the table back into our array
- $table_info[$table_name] = $table;
- }
- // Update session with new data
- $_SESSION['table_info'] = $table_info;
- echo '<pre>';
- print_r($table_info);
- echo '</pre>';
- ?>
Cela nécessite que vos liens donner un nom de table, champ pour le tri et la façon dont vous voulez qu'il soit trié.
#define NULL (::rand() % 2)
- SpooF
- ٩๏̯͡๏۶


- Inscription: Mai 22, 2004
- Messages: 3415
- Loc: Richland, WA
- Status: Offline
Heres some out mis à partir de quelques tests:
Code: [ Select ]
// Link: http://192.168.1.200/table_session.php?table=Data&order_by=Field1&sorting=desc
// Output
Array
(
[Data] => Array
(
[order_by] => Field1
[sorting] => desc
)
)
// Link: http://192.168.1.200/table_session.php?table=Data&order_by=Field2&sorting=desc
// Output
Array
(
[Data] => Array
(
[order_by] => Field2
[sorting] => desc
)
)
// Link: http://192.168.1.200/table_session.php?table=Users&order_by=Field1&sorting=asc
// Output
Array
(
[Data] => Array
(
[order_by] => Field2
[sorting] => desc
)
[Users] => Array
(
[order_by] => Field1
[sorting] => asc
)
)
// Output
Array
(
[Data] => Array
(
[order_by] => Field1
[sorting] => desc
)
)
// Link: http://192.168.1.200/table_session.php?table=Data&order_by=Field2&sorting=desc
// Output
Array
(
[Data] => Array
(
[order_by] => Field2
[sorting] => desc
)
)
// Link: http://192.168.1.200/table_session.php?table=Users&order_by=Field1&sorting=asc
// Output
Array
(
[Data] => Array
(
[order_by] => Field2
[sorting] => desc
)
[Users] => Array
(
[order_by] => Field1
[sorting] => asc
)
)
- // Link: http://192.168.1.200/table_session.php?table=Data&order_by=Field1&sorting=desc
- // Output
- Array
- (
- [Data] => Array
- (
- [order_by] => Field1
- [sorting] => desc
- )
- )
- // Link: http://192.168.1.200/table_session.php?table=Data&order_by=Field2&sorting=desc
- // Output
- Array
- (
- [Data] => Array
- (
- [order_by] => Field2
- [sorting] => desc
- )
- )
- // Link: http://192.168.1.200/table_session.php?table=Users&order_by=Field1&sorting=asc
- // Output
- Array
- (
- [Data] => Array
- (
- [order_by] => Field2
- [sorting] => desc
- )
- [Users] => Array
- (
- [order_by] => Field1
- [sorting] => asc
- )
- )
#define NULL (::rand() % 2)
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Holy crap...LOL! J'ai juste commencé à apprendre le PHP ce dimanche passé et je suis très occupé avec l'ATM travail, donc il va me falloir un peu de temps pour digérer tout cela et le programme d'installation quelque chose.
Merci une tonne pour toute l'aide si loin! Maintenant, ma famille peut être fière de mon geekness et peut-être m'acheter un jeu Wii tout en theyre at it!
Merci une tonne pour toute l'aide si loin! Maintenant, ma famille peut être fière de mon geekness et peut-être m'acheter un jeu Wii tout en theyre at it!
- kingdutka
- Newbie


- Inscription: Mar 06, 2010
- Messages: 10
- Loc: USA
- Status: Offline
Donc, Ive a obtenu tout ce travail, mais j'ai maintenant besoin d'ajouter dans un "tri secondaire". Je comprends comment il fonctionne dans SQL, mais pas en PHP. Je cherche moins une ligne de code en particulier:
Que ferais-je ajouter à l'URL PHP pour donner un second tri comme vous voyez dans l'exemple #4 ici:
techonthenet. com / sql / order_by.php
Code: [ Select ]
echo ("<TH><a href=\"$page.php?order_by=$field_name&sorting=$sort&tablename=$tablename\">$field_name</a></TH>");
Que ferais-je ajouter à l'URL PHP pour donner un second tri comme vous voyez dans l'exemple #4 ici:
techonthenet. com / sql / order_by.php
Page 1 sur 1
Pour répondre à ce sujet, vous devez vous connecter ou vous enregistrer. Il est gratuit.
Afficher de l'information
- Total des messages de ce sujet: 13 messages
- Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 140 invités
- Vous ne pouvez pas poster de nouveaux sujets
- Vous ne pouvez pas répondre aux sujets
- Vous ne pouvez pas éditer vos messages
- Vous ne pouvez pas supprimer vos messages
- Vous ne pouvez pas joindre des fichiers

