Register|Login

Have a question? Click here to ask the community.

Tutorial 7 – MySQL Order By

| In: 7. Database Order By | 5,194 views

Video Tutorial


Video Source Code

File: viewContacts.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
// MySQL Tutorial 7 - Selecting Data From A Database With The ORDER BY keyword
 
/* Syntax
SELECT columnNames FROM tableName
ORDER BY columnName(s) ASC|DESC
*/
 
include("header.php"); // include header links
include("config.php"); // connect to database
 
$result = mysql_query("SELECT * FROM contacts WHERE firstName='Sally' ORDER BY zipCode DESC")
                    or die (mysql_error());
 
while ($row = mysql_fetch_array($result)) {
    echo "Name: $row[firstName] $row[lastName] <br>";
    echo "Phone Number: $row[phoneNumber] <br>";
    echo "Zip Code: $row[zipCode]";
    echo "<br><br>";
}
?>



2 Responses to Tutorial 7 – MySQL Order By

Avatar

ka9584

June 12th, 2015 at 3:32 pm

how can you make a search engine on the view contacts page? lets say- you would be able to select on the view contacts page (lastName, firstName,etc) and pull it out from the database?

Avatar

mhmd

August 29th, 2016 at 7:16 am

can we become a pro with these videos? i watched them all. is that it?

Comment Form

You must be logged in to post a comment.