Results 1 to 3 of 3

Thread: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

  1. #1
    Senior Member
    nixsham's Avatar
    Join Date
    Aug 2008
    Location
    syok.org
    Posts
    411
    Post Thanks / Like

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?php
    $hostname_doktor = 'localhost';
    $username_doktor = 'root';
    $password_doktor = '';
    $conn = mysql_connect($hostname_doktor, $username_doktor,$password_doktor) or die ('Error connecting to mysql');
    $database_doktor = 'doktor';
    mysql_select_db($database_doktor);

    $limit = 2;
    if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
    $start_from = ($page-1) * $limit;

    $negara=(isset($_POST['negara']));
    $IdWarga=(isset($_POST['IdWarga']));

    $query = ("SELECT * FROM warganegara WHERE IdWarga = '$IdWarga' ORDER BY $IdWarga");
    $result = mysql_query ($query);
    ?>
    <table class="table table-bordered table-striped">
    <thead>
    <tr>
    <th>title</th>
    <th>body</th>
    </tr>
    <thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($result)) { <---error
    ?>
    <tr>
    <td><? echo $row["title"]; ?></td>
    <td><? echo $row["body"]; ?></td>
    </tr>
    <?php
    };
    ?>
    </tbody>
    </table>
    <?php
    $query = "SELECT COUNT(negara) FROM warganegara";
    $result = mysql_query($query);
    //$row = mysql_fetch_row($result);
    $total_records = $row[0];
    $total_pages = ceil($total_records / $limit);
    $pagLink = "<div class='pagination'>";
    for ($i=1; $i<=$total_pages; $i++) {
    $pagLink .= "<a href='add_warganewAdmin.php?page=".$i."'>".$i."</a>";
    };
    echo $pagLink . "</div>";
    ?>

    </body>
    </html>


    otai php tulun..

  2. #2
    Senior Member
    nixsham's Avatar
    Join Date
    Aug 2008
    Location
    syok.org
    Posts
    411
    Post Thanks / Like
    error tu dh ok sbb tukar query to select all je...sptt ade limit utk 1 page cam 10 data di paparkan n ble klik next 10 data lg di paparkan..tp yg jd problemnye seme data kluar skaligus n fungsi paginating x de...ni kod nye

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?php
    $hostname_doktor = 'localhost';
    $username_doktor = 'root';
    $password_doktor = '';
    $conn = mysql_connect($hostname_doktor, $username_doktor,$password_doktor) or die ('Error connecting to mysql');
    $database_doktor = 'doktor';
    mysql_select_db($database_doktor);

    $limit = 10;
    if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=5; };
    $start_from = ($page-5) * $limit;

    $negara=(isset($_POST['negara']));
    $IdWarga=(isset($_POST['IdWarga']));

    $query = ("SELECT * FROM warganegara") or die (mysql_error());
    $result = mysql_query ($query);


    ?>
    <table class="table table-bordered table-striped">
    <thead>
    <tr>
    <th>title</th>
    <th>body</th>
    </tr>
    <thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($result)) {
    ?>
    <tr>
    <td><?php echo $row['IdWarga']; ?></td>
    <td><?php echo $row['negara']; ?></td>
    </tr>
    <?php
    };
    ?>
    </tbody>
    </table>
    <?php
    $query = "SELECT COUNT(negara) FROM warganegara";
    $result = mysql_query($query);
    $row = mysql_fetch_row($result);
    $total_records = $row[0];
    $total_pages = ceil($total_records / $limit);
    $pagLink = "<div class='pagination'>";
    for ($i=5; $i<=$total_pages; $i++) {
    $pagLink .= "<a href='add_warganewAdmin.php?page=".$i."'>".$i."</a>";
    };
    echo $pagLink . "</div>";
    ?>

    </body>
    </html>

  3. #3
    Senior Member
    Akirien's Avatar
    Join Date
    Aug 2007
    Posts
    157
    Post Thanks / Like

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com
    Please use code tags to display the codes neatly

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?php 
    $hostname_doktor 
    'localhost'
    $username_doktor 'root'
    $password_doktor ''
    $conn mysql_connect($hostname_doktor$username_doktor,$password_doktor) or die ('Error connecting to mysql'); 
    $database_doktor 'doktor'
    mysql_select_db($database_doktor); 

    $limit 10
    if (isset(
    $_GET["page"])) { $page $_GET["page"]; } else { $page=5; }; 
    $start_from = ($page-5) * $limit

    $negara=(isset($_POST['negara']));
    $IdWarga=(isset($_POST['IdWarga']));

    $query = ("SELECT * FROM warganegara") or die (mysql_error()); 
    $result mysql_query ($query);


    ?> 
    <table class="table table-bordered table-striped"> 
    <thead> 
    <tr> 
    <th>title</th> 
    <th>body</th> 
    </tr> 
    <thead> 
    <tbody> 
    <?php 
    while ($row mysql_fetch_assoc($result)) { 
    ?> 
    <tr> 
    <td><?php echo $row['IdWarga']; ?></td>
    <td><?php echo $row['negara']; ?></td> 
    </tr> 
    <?php 
    }; 
    ?> 
    </tbody> 
    </table> 
    <?php 
    $query 
    "SELECT COUNT(negara) FROM warganegara"
    $result mysql_query($query); 
    $row mysql_fetch_row($result); 
    $total_records $row[0]; 
    $total_pages ceil($total_records $limit); 
    $pagLink "<div class='pagination'>"
    for (
    $i=5$i<=$total_pages$i++) { 
    $pagLink .= "<a href='add_warganewAdmin.php?page=".$i."'>".$i."</a>"
    }; 
    echo 
    $pagLink "</div>"
    ?> 

    </body>
    </html>

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •