9951 explained code solutions for 126 technologies


php-mysqlHow to order by a column in ascending order in MySQL using PHP?


To order by a column in ascending order in MySQL using PHP, the following code can be used:

$sql = "SELECT * FROM table_name ORDER BY column_name ASC";
$result = mysqli_query($conn, $sql);

This code will output the data from the table in ascending order based on the specified column.

The code consists of the following parts:

  1. $sql: This is the SQL query that is used to select all the data from the table and order it in ascending order based on the specified column.

  2. $result: This is the result of the query that is stored in a variable.

  3. mysqli_query($conn, $sql): This is the function that is used to execute the query and store the result in the $result variable.

Helpful links

Edit this code on GitHub