A
A
Arthur2016-01-20 22:50:57
PHP
Arthur, 2016-01-20 22:50:57

How to make a selection from the database?

Hello, I have a question, how to correctly select the last 10 from the database, I know, but how to make the output a list in order, that is, sort the last 10 if the id is not static. i.e. assign each entry to every 10 variables. For example $1 = first entry, $2 = second, etc. In the direction of arrays to think?
---
ps
Sampling the last ten ("SELECT * FROM stats ORDER BY id DESC LIMIT 10");
It is necessary to make a list from these last 10, but each name from these ten must have a container with a certain background, and display with a pyramid a la
1
2.3
4.5.6
7.8.9.10

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2016-01-20
@Rsa97

ORDER BY ... DESC
LIMIT 10

A
Andrey, 2016-01-21
@VladimirAndreev

$step = 1;
$data = [ $step => [] ];
for($i=0; isset($data[$i]; ++$i) {
    $data[$step][] = $data[$i];
    if(count($data[$step]) == $step) {
        ++$step;
        $data[$step] = [];
    }
}

A
Artur, 2016-01-24
@arturka_v_10

made shitcode:
(fastening the table status and increasing it from the previous one when adding a new row)
$db->Query("SELECT * FROM db_pyramid WHERE status = 1");
$stat1 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 2");
$stat2 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 3");
$stat3 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 4");
$stat4 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 5");
$stat5 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 6");
$db->Query("SELECT user FROM db_pyramid WHERE status = 7");
$stat7 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 8");
$stat8 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 9");
$stat9 = $db->FetchArray();
$db->Query("SELECT user FROM db_pyramid WHERE status = 10");
$stat10 = $db->FetchArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question