1

Hi i have got little problem with my MySQL database.
I have got these things in my database : enter image description here

When i have code :

$show_name = "SELECT name FROM serverlist_comments WHERE location = 1";
$result = mysqli_query($conn,$show_name);
$show_carriage = "SELECT carriage FROM serverlist_comments WHERE location = 1 ORDER BY datetime";
$result_carriage = mysqli_query($conn,$show_carriage);
while($row_name = mysqli_fetch_assoc($result)){
while($row_carriage = mysqli_fetch_assoc($result_carriage)){
       print($row_name['name']);
       echo " napísal/a toto : ";
       print($row_carriage['carriage']);
       echo "<br/>";
}
}
?>

i will receive output :
"Kubajsk0 napísal/a toto : ok
Kubajsk0 napísal/a toto : niet
Kubajsk0 napísal/a toto : ale "

I know it is everything ok cause in date/time 18:17:29 (as "ok") is first and date/time 18:17:32 (as "niet") comes after it


BUT i want to have JUST THE OPPOSITE of this output.
I want output to be:
"Kubajsk0 napísal/a toto : ale
Kubajsk0 napísal/a toto : niet
Kubajsk0 napísal/a toto : ok"

Thank you for every answer :D

1
  • 2
    You need to read the docs or do a bit more searching before asking a question. Commented Dec 15, 2014 at 17:57

3 Answers 3

2

You should add direction to your query: SELECT carriage FROM serverlist_comments WHERE location = 1 ORDER BY datetime DESC

DESC means descending, ASC means ascending.

Sign up to request clarification or add additional context in comments.

Comments

2

maybe descending order like:

ORDER BY datetime DESC

or:

ORDER BY datetime ASC

for ascending order

Comments

2

I don't understand why you have two loops. If you want to get the output like:

Kubajsk0 napísal/a toto : ale
Kubajsk0 napísal/a toto : niet
Kubajsk0 napísal/a toto : ok

you can use following code.

$show_carriage = "SELECT name, carriage FROM serverlist_comments WHERE location = 1 ORDER BY datetime DESC";
$result_carriage = mysqli_query($conn,$show_carriage);
while($row_carriage = mysqli_fetch_assoc($result_carriage)){
       echo $row_carriage['name'];
       echo " napísal/a toto : ";
       echo $row_carriage['carriage'];
       echo "<br/>";
}

5 Comments

Inak som Slovák tak môžeš aj po slovensky
Ok, ty dva while v sobě nebyly potřeba. Obě informace můžeš vytáhnout jedním dotazem. Ale to už teď asi vidíš sám.
Jinak DESC je zkratka v dotaze pro řazení descending (sestupně) od nejvyšší hodnoty po nejnižší. Pokud v SQL dotaze nezvolíš řazení, použije se výchozí ASC ascending.
Ok, ty by si zase mohl označit můj příspěvek jako řešení.
Dal jsem ti like na příspěvek a posunul všechny komenty. To je asi vše co můžu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.