Jump to content

Recommended Posts

I have a table that contains data from my database. I was wondering if there was a way that I could make the headers (name, date joined, expiry date and fee) control the order of the data in both ascending and descending order. And make the which header is organizing the data currently look different (ie. when data is organized by name...name is bold while other headers are not). I've tried searching for how to do this...but have had no luck with actually accomplishing it.

 

I'd appreciate any help.

 

Thanks

 

 

 

Here is my code:

<?php 
print' 
<table class="myTable"> 
    <thead> 
     
    <th scope="col"><h2>Name</h2></th> 
    <th scope="col"><h2>Phone Number</h2></th> 
    <th scope="col"><h2>Email</h2></th> 
    <th scope="col"><h2>Date Joined</h2></th> 
    <th scope="col"><h2>Expiry Date</h2></th> 
    <th scope="col"><h2>Fee Paid</h2></th> 
    <th scope="col"><h2>Edit</h2></th> 
    <th scope="col"><h2>Delete</h2></th> 
     
    </thead>'; 
     
     
    $sql = "SELECT name, phone, email, date_joined, expiry_date, fee FROM customer ORDER BY name"; 
     
     
    $qry = mysql_query($sql); 
     
    if (mysql_num_rows($qry) > 0) { 
        while ($rs = mysql_fetch_assoc($qry)) { 
             
             
            print' 
            <td>' . $rs['name'] . '</td> 
            <td>' . $rs['phone'] . '</td> 
            <td>' . $rs['email'] . '</td> 
            <td>' . $rs['date_joined'] . '</td> 
            <td>' . $rs['expiry_date'] . '</td> 
            <td>' . $rs['fee'] . '</td> 
            <td><a href="edit.php">Edit</a></td> 
            <td><a href="delete.php">Delete</a></td><tr>'; 
        } 
    } else { 
        print '<h4>no result found</h4>'; 
    } 
print' 
</table>'; 
?>

 

Something like..

 

$query="SELECT * FROM whatever ORDER BY $col DESC";

 

In your table

 

    <th scope="col"><h2><a href="pagename.php?col=name">Name</a></h2></th> 
    <th scope="col"><h2><a href="pagename.php?col=phone">Phone Number</a></h2></th>

 

etc..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.