Hi m8
I seen this code on codewalkers.com, very useful.
<?
session_start();
$default_sort = 'story_id';
$allowed_order = array ('story_id', 'author');
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}
$_SESSION['order'] = $order;
// This will be the sorting part, you make a link index.php?order=author.
/* connect to db */
mysql_connect ('localhost','user','pass');
mysql_select_db ('test');
// Set these to your settings.
/* construct and run query */
$query = "SELECT * FROM sometable ORDER BY $_SESSION['order']";
$result = mysql_query ($query);
/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
echo "No data to display!";
exit;
}
/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
/* check if the heading is in our allowed_order
* array. If it is, hyperlink it so that we can
* order by this column */
echo "<TD><b>";
if (in_array ($heading, $allowed_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
echo "</TR>\n";
/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
You will just need to go into your mysql db and add a column named story_id as (INT) with auto_increment for numbers.
Add which fields you want inside the array.
If you want to see this tutorial so it make more sense. Go to
www.codewalkers.com > tutorials > database.
Sorting data tutorial.
Hope this helps m8.
Ill pm ya l8r to help you with inserting data into database and adding new fields if you want. Just give me a pm m8
Cya
Paul