Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209

    Order by "THIS", and sort from z-a

    Hi,

    I have the order part, now how would I sort the column "out1" from z-a?

    Code:
    <table style="width: 134%; height: 137px">	<tr>
    	<div id="pageMiddle" style="clear:left; line-height:1.5em; width:92%; margin:40px auto;">
    
    
    			
    	</div>
    
    
    		<td style="width: 387px">
    		</td>
    
    
    		<td style="width: 628px">
            <p>Sorts by out first (No, Yes), Then by name.</p><br>
            <p><b>View All</b> | <a href="view-paginated.php">View Paginated</a> | <a href="records.php">New Record</a></p>
    
    
                    
                    <?php
                            // connect to the database
                            include('connect-db.php');
                            
                            // get the records from the database
                            if ($result = $mysqli->query("SELECT * FROM equipment ORDER BY out1,name"))
                            {
                                    // display records if there are records to display
                                    if ($result->num_rows > 0)
                                    {
                                            // display records in a table
                                            echo "<table border='1' cellpadding='10' class='db-table'>";
                                            
                                            // set table headers
                                            echo "<tr><th>ID</th><th>Name</th><th>Type</th><th>Out</th><th>Outbywho</th><th>Status</th><th></th><th></th></tr>";
                                            
                                            while ($row = $result->fetch_object())
                                            {
                                                    // set up a row for each record
                                                    echo "<tr>";
                                                    echo "<td>" . $row->id . "</td>";
                                                    echo "<td>" . $row->name . "</td>";
                                                    echo "<td>" . $row->type . "</td>";
                                                    echo "<td>" . $row->out1 . "</td>";
                                                    echo "<td>" . $row->outbywho . "</td>";
                                                    echo "<td>" . $row->stat . "</td>";
                                                    echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
                                                    echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
                                                    echo "</tr>";
                                            }
                                            
                                            echo "</table>";
                                    }
                                    // if there are no records in the database, display an alert message
                                    else
                                    {
                                            echo "No results to display!";
                                    }
                            }
                            // show an error if there is an issue with the database query
                            else
                            {
                                    echo "Error: " . $mysqli->error;
                            }
                            
                            // close database connection
                            $mysqli->close();
                    
                    ?>
                    
                    
    
    
    		</td>
    		<td>&nbsp;</td>
    	</tr>
    </table>
    Thanks!

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    ORDER BY out1 DESC (desc sorts by descending order.)
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:25 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com