2

This is code which is trying to fetching data from DB. but getting error mysql_fetch_array() expects parameter.

<?php
    $sql="select * from admin_slider where status_name=1 and (end_date>=CURDATE() or unlimited=1)order by position asc";
    $result_set=mysql_query($sql);
    while($row=mysql_fetch_array($result_set))
    {
?>
<div data-p="225.00" style="display: none;">
    <img data-u="image" src="images/slideruploads/<?php echo $row['file'];?>" />
</div>
<?php  } ?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • Possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource (or mysqli\_result), boolean given](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-or-mysqli-result-boole) –  Feb 15 '16 at 06:38
  • run this query in php myadmin.. chk r u getting results or not. select * from admin_slider where status_name=1 and (end_date>=CURDATE() or unlimited=1)order by position asc – devpro Feb 15 '16 at 06:38
  • 1
    first stop using `mysql_*` deprecated now. Use `mysqli_*` or `PDO`. also add `error_reporting(E_ALL);ini_set('display_errors',1);` just after ` – Alive to die - Anant Feb 15 '16 at 06:38
  • yes i run the query it run currectly @devpro –  Feb 15 '16 at 06:41
  • where i can place mysql_* –  Feb 15 '16 at 06:41

1 Answers1

0

There is a syntax error in your query. So $result_set is not a mysql resource any more. mysql_fetch_array() expectes parameter to be an mysql resource. But in your case it is not resource. Corrected the syntax.

<?php
    $sql="SELECT * 
            FROM  admin_slider 
           WHERE  status_name=1 
             AND ( end_date>=CURDATE() OR unlimited=1)
        ORDER BY position ASC";
    $result_set = mysql_query($sql) or (die(mysql_error()));
    while($row=mysql_fetch_array($result_set)) {
?>
        <div data-p="225.00" style="display: none;">
            <img data-u="image" 
                 src="images/slideruploads/<?php echo $row['file'];?>" />
       </div>
       <?php
    }
?>

Also note: mysql_query is depreciated. Move to PDO or mysqli.

Dinesh Patra
  • 1,125
  • 12
  • 23
  • Dinesh your code execute but when enter while loop it will false –  Feb 15 '16 at 06:51
  • nope Dinesh. just stopped, i think while not executed, –  Feb 15 '16 at 06:56
  • ya because there is no result found, that's why the while loop is not executed. try to print mysql_num_rows( $result_set); to get how many rows has been fetched . Print after this statement $result_set = mysql_query($sql) or (die(mysql_error())); – Dinesh Patra Feb 15 '16 at 06:57