Data from SQL in alphabetical order
Discuss coding issues, and scripts related to PHP and MySQL.
-
JanMolendijk
- Posts: 267
- Location: Holland Rotterdam
Data from SQL in alphabetical order
Plessant Coursesweb,
I have an grouplist in my database from country`s.
First time I did not do any search-study for this questionm but ask you straitly....
I would like to have my list in alphabetical order.
Can this be easely done into this code ?
Code: Select all
<?php
// connect to the "tests" database
$conn = new mysqli('127.0.0.1', 'comments', '123456', 'comments');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// SELECT sql query
$sql = "SELECT * FROM `w3_post` where group_id='40' ORDER BY `w3_post`.`post_id` DESC";
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
// output data of each row from $result
while($row = $result->fetch_assoc()) {
echo '
'. $row['title']. ' <br><br> ' ;
}
}
else {
echo ' okkok';
}
$conn->close();
?>
MarPlo
Try this sql query:
Code: Select all
$sql = "SELECT * FROM `w3_post` where group_id='40' ORDER BY `w3_post`.`country` ASC";
- 'country' is the column you want in alphabetical order.
JanMolendijk
Is it because ASC it sets on alpha ????
I always thought ASC only do the numberal-thig
Because I just did this
Code: Select all
SELECT * FROM `w3_post` where group_id='40' ORDER BY `w3_post`.`title` ASC
& it worked please some explain ????
MarPlo
If you apply ORDER BY to a column with letters, it will sort the results alphabetically (ASC or DESC).
HayatAnsiklopedisi
Me too want to numeric order. Can u help me?
MarPlo
@HayatAnsiklopedisi , post the SQL query you have, and explain what result you want to get.
Similar Topics
-
Execution order with jQuery-AJAX
JavaScript - jQuery - Ajax
First post
I have this code (ajax is async):
function echoHello(){
return $.ajax({
//this will return hello ;
});
}
function echoWorld(){
return world...
Last post
Ajax makes a call to the web server and is asynchronous. You don't know how long it will take. It is the same as:
setTimeout(_ => {...
-
SSEP - BUT Cannot save its Page Data
Scripts from this website
First post
Every time I try to index the site it comes back with this message for some of the pages:
BUT Cannot save its Page Data
It indexed 323 pages but...
Last post
nice, and nice script, you know what your doing
If you ever want to write a post, article or blog...
Maybe on PHP Resources ?
Id be glad to add it...
-
Delete Data without Refreshing Page
JavaScript - jQuery - Ajax
First post
Happy New Year Chief.... My first two weeks I spended on bed due to illness
I wanna use a script but it does not delete the item from my sql...
Last post
O God that I did not see this `stupido me`....
Thank you very much for all the support `its working now`
-
Hide element if data contains specific text
HTML - CSS
First post
Is there a possibility to hide HTML elements if the 'data-' attribute contains a specific piece of text?
For example: Hide the Divs that it's data...
Last post
You can do this with either CSS or Javascript.
CSS:
/* with specified elements */
div {
display: none;
}
/* or global */
{
display: none;...
-
New computer chip process and store data like a neuron
Entertainment and Games
Engineers at EPFL have created a new computer chip that can both process and store data in the same circuit. It’s made using a two-dimensional...