Good day.
I want to sort the news by date and name, but it does not work, or rather if you put ORDER BY $order_db in the query, then the output of the news stops altogether, but stops because of $order_db , an error occurs. Although this sorting is for another, everything works there. Here is the code:
/* =====Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ°===== */ $order_p = array( 'datea' => array('ΠΏΠΎ Π΄Π°ΡΠ΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ - ΠΊ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΠΌ', 'date ASC'), 'dated' => array('ΠΏΠΎ Π΄Π°ΡΠ΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ - Ρ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΡ
', 'date DESC'), 'titlea' => array('ΠΎΡ Π Π΄ΠΎ Π―', 'title ASC'), 'titled' => array('ΠΎΡ Π― Π΄ΠΎ Π', 'title DESC') ); $order_get = clear($_GET['order']); // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΡΠΉ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠΈ if(array_key_exists($order_get, $order_p)){ $order = $order_p[$order_get][0]; $order_db = $order_p[$order_get][1]; }else{ // ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ ΡΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΠΏΠΎ ΠΏΠ΅ΡΠ²ΠΎΠΌΡ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° order_p $order = $order_p['datea'][0]; $order_db = $order_p['datea'][1]; } /* =====Π‘ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ°===== */ $all_news = news($order_db); function news($order_db){ global $connection; $query = "SELECT news_id, title, anons, date FROM news ORDER BY $order_db DESC LIMIT $start_pos, $perpage"; $res = mysqli_query($connection, $query); $all_news = array(); while($row = mysqli_fetch_assoc($res)){ $all_news[] = $row; } return $all_news; } Well, the sorting output itself:
Π‘ΠΎΡΡΠΈΡΠΎΠ²Π°ΡΡ: <ul id="menuuu"> <li><?=$order?> <ul> <?php foreach($order_p as $key => $value): ?> <?php if($value[0] == $order) continue; ?> <li><a href="ΡΡΡΠ»ΠΊΡ ΠΏΠΎΡΠΎΠΌ ΠΏΡΠΎΠΏΠΈΡΡ" class="sort-bot"><?=$value[0]?></a></li> <?php endforeach; ?> </ul> </li> </ul> Who can find a mistake, tell me, please. )