How to arrange to organize the array() ?

Hello there is a problem.
There is a database query *$query ="SELECT * FROM menu ORDER BY position"
if($result = mysqli_query($connection, $query)){
$menu_all = array();
while ($row = $result->fetch_assoc()){
$menu_all[] = $row;
}
}.

The problem is that in this table there is a field under which default is *0* and like in the query to specify that all lines with "under == 0" are valid in one array and those where "under > 0" go in the other array.
Thank you
September 26th 19 at 11:55
4 answers
September 26th 19 at 11:57
Solution
In the cycle
if($row['under'] == 0){
$var_s_0_all[] = $row;
} else {
$var_bez_0_all[] = $row;
}
exactly how do it thank you - hailee_Altenwerth commented on September 26th 19 at 12:00
September 26th 19 at 11:59
Solution
One request -one response. One request two responses - mine is something new)
1) two requests
2)array divide themselves into two
3) too much put need condition
September 26th 19 at 12:01
Solution
In the query - no way.
Two options:
Or read any basic tutorial on sql, until the article in Wikipedia and to make 2 the query.
Or you can leave the query as is and sort the result arrays yourself.

Sorry, couldn't resist.
Even in Wikipedia there are articles about punctuation and case. But what to do with the flow of the sentences, I will not advise.
Yes, thank you the fact that I already forget the Russian slowly since left the country when I was a kid. so Yes, I admit it - hailee_Altenwerth commented on September 26th 19 at 12:04
September 26th 19 at 12:03
Solution
Three people have the right answer, I would add.
1. Not write so, there is a risk of running into reserved words:
SELECT * FROM menu ORDER BY position
A better way:
SELECT * FROM `menu` ORDER BY `position`

2. Do not use mysql_xxx, mysqli_xxx, pg_xxx, msql_xxx. For example, with MySQLi You need to migrate to a different database, such as MSSQL server. Will throughout the code to look for these mysqli_ and change. A better way:
$pdo = new PDO('mysql:host=locahost;dbname=mydatabase', 'user', 'passsword');
$query->prepare('SELECT * FROM `menu` ORDER BY `position`);
$query->execute();
$menu_all = $query->fetchAll(PDO::FETCH_ASSOC);

So You will not particularly depend on the database, and there is a plus to transfer the parameters to the query - no need to worry about avoiding SQL injection.
Thank you - hailee_Altenwerth commented on September 26th 19 at 12:06

Find more questions by tags MySQLPHP