1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\

Discussion in 'MySQL' started by es-es, Jun 21, 2012.

  1. #1
    <?php
    mysql_select_db('haberler' ,mysql_connect('localhost','root','')) or die(mysql_error());
    $sayfa = intval($_GET['sayfa']);
    $toplam = mysql_num_rows(mysql_query("select * from haberler"));
    $limit = 5;
    $goster = $sayfa * $limit - $limit;

    $query = mysql_query("select * from haberler limit $goster,$limit");

    while($row = mysql_fetch_array($query)){

    echo 'span class="haber">'.$row['haberler'].'</span>';


    }
    ?>

    this code gets the error:
    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pagination\index.php on line 10
    how to fix it please help!

    how can i fix that arror? please help!
     
    Solved! View solution.
    es-es, Jun 21, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Means your query failed. You need to error out the query and see what's the problem.

    Replace:

    $query = mysql_query("select * from haberler limit $goster,$limit");
    PHP:
    with

    if(!$query = mysql_query("select * from haberler limit $goster,$limit")) {
    die(mysql_error());
    };
    PHP:
     
    jestep, Jun 22, 2012 IP
  3. #3
    im pretty sure that your echo line needs some tweaking

    echo "span class=\"haber\">" . $row['haberler'] . "</span>";
    PHP:
    i couldnt see any use for this:
    $toplam = mysql_num_rows(mysql_query("select * from haberler"));
    PHP:
    perhaps just comment it out while you work on it.

    try commenting out sayfa and replace it with sayfa = 5 (or other fixed number) just makes sure that it has a variable attached.

    or replace the get sayfa line with:
    $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa'];
    PHP:
     
    matt_62, Jun 22, 2012 IP
  4. es-es

    es-es Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @matt_62;your $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa']; code line solved this error: Notice: Undefined index: sayfa in C:\xampp\htdocs\pagination\index.php on line 3 , but real problem is with while ($row = mysql_fetch_array($query)) code line.PHP notices me by this code line, this code line 10.
     
    es-es, Jun 22, 2012 IP
  5. es-es

    es-es Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    @jestep your proposal caused a new error that is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5,5' at line 1
     
    es-es, Jun 22, 2012 IP
  6. matt_62

    matt_62 Prominent Member

    Messages:
    1,827
    Likes Received:
    515
    Best Answers:
    14
    Trophy Points:
    350
    #6
    sadly sql is not my strong point, in fact ive never seen or heard of "limit" before.

    If this doesnt help you then your on your own. But i think you might have your database name, table name as well as the field names confused.
    If this helps you let me know, if it doesnt then im unable to help you.

    <?php
    // get sayfa
    $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa'];
    $limit = 5;
    
    //get connection details
    include("mysqlconnection.php");  // save your connection details in here
    
    $mysqli    = mysqli_connect($host, $user, $pwd);
    if (!$mysqli)
      {
      die('Could not connect: ' . mysql_error());
      }
      
    mysqli_select_db($db, $mysql);
    
    $query = mysqli_query("select * from TABLENAME_NOT_DATABASE_NAME where TABLENAME.FIELD_NAME < '$goster' and  TABLENAME.FIELD_NAME > '$limit'");
    
    $result    = mysqli_query($mysqli, $query);        
    while($row=mysqli_fetch_array($result))
    { print "testing";}
    ?>
    
    //save these details under mysqlconnection.php
    <?php
    // this just makes it easy to modify the connection details site wide if details change
    $host    ="localhost";
    $user    ="root";
    $pwd    ="";
    $db        ="haberler";
    ?>
    PHP:
     
    matt_62, Jun 22, 2012 IP
  7. es-es

    es-es Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thank you very much all of you, i have solved the problem. i realised not set the code if(!$sayfa) $sayfa = 1; in the string. but i learnt lots of your replays...
     
    es-es, Jun 23, 2012 IP