0

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)){ 
?>
4
  • 3
    Your SQL query is wrong. just try to get the query alone working in something like PHPmyAdmin and then insert it into your code. First question you should ask yourself: How should the database know by which column to sort ... Commented Jun 22, 2016 at 7:56
  • 1
    Are you forced to work with mysql_* functions ? Because you should consider using latest secure mysql driver such as PDO or MySQLi. Commented Jun 22, 2016 at 7:58
  • Please head to the manual page for mysql_query() and scroll down the do not use this extension warning to "Example #1". There's a simple usage example. Commented Jun 22, 2016 at 8:11
  • What Alex said :) But best to avoid using [mysql_fetch_array ](php.net/manual/en/function.mysql-fetch-array.php) as it is deprecated, use mysqli_fetch_array instead. Commented Jun 22, 2016 at 14:19

2 Answers 2

2

your mysql_query is returning an error, to order just use ORDER BY your_field_name DESC instead of DESC()

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.