L
L
Lulzsec2018-02-06 01:52:52
PHP
Lulzsec, 2018-02-06 01:52:52

Sort table by column via mysql and php?

There is a table in the database
5a78dfd105d7e305337086.jpeg
How to get this in PHP?
Fruit:
Apple
Pear
Orange
Vegetable:
Tomato
Cucumber
Onion
The problem is in sorting on PCP, I know how to get data from the database..

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-02-06
@Stalker_RED

select * from my_table ORDER BY my_column

A
Ainur Valiev, 2018-02-06
@vaajnur

function cmp($a, $b)
{
    return strcmp($a["cat"], $b["cat"]);
}
usort($arr, "cmp");

A
Alexander, 2018-02-06
@AK-VoronM

$arr = [];
foreach ($res as $k=>$val) {
    if (!array_key_exist($val['type'], $arr)) {
         $arr[$val['type']] = [];
    }
    $arr[$val['type']][] = $val['name'];
}

Get an associative array broken down by type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question