Fadlhy MJ Fadlhy MJ - 5 months ago 23
PHP Question

How to sort data mysql in php syntax


Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in C:\xampp\htdocs\techponya\index.php on line x


<?php
$sql2 = "SELECT * FROM artikel WHERE kategori='technews' DESC() LIMIT 5";
$hasil2 = mysql_query($sql2,$dbconn);
while ($techponya = mysql_fetch_array($hasil2)){
?>

Answer

1.Stop using deprecated (From php 5 version onwards)+removed(From php 7) mysql_*. Use mysqli_* OR PDO

2.Use ORDER BY along with DESC:-

<?php 
  $sql2 = "SELECT * FROM artikel WHERE kategori='technews' ORDER BY <write your column name here> DESC LIMIT 5";
  $hasil2 = mysql_query($sql2,$dbconn);
  while ($techponya = mysql_fetch_array($hasil2)){
    // do some stuff 
  }
?>

3.Also always do error checking code stuff too.

reference:-

http://www.w3schools.com/php/php_ref_mysqli.asp