Fatal error: Call to a member function fetch_assoc() on boolean

Jadi saya ingin memasukkan script PHP ke dalam wordpress (masih di localhost), disini saya menggunakan plugin "Insert PHP" Nah begitu di execute, terjadi error Fatal error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\wordpress\wp-content\plugins\insert-php\insert_php.php(48) : eval()'d code on line 69 Ada yang tau cara mengatasinya ? Terima Kasih

avatar gbagoes
@gbagoes

3 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

coba liat kodenya gan

avatar BroGoeh
@BroGoeh

121 Kontribusi 47 Poin

Dipost 6 tahun yang lalu

 [insert_php]
$host = "localhost"; //database location
$user = "root"; //database username
$pass = ""; //database password
$db_name = "calendar"; //database name

//Database Connection
$connection = mysql_connect($host, $username, $password);
mysql_select_db($dbname);

function kalender($month, $year, $numOfDays)
{

    // Create array containing abbreviations of days of week.
    $daysOfWeek = array('S', 'M', 'T', 'W', 'T', 'F', 'S');

    $curDay = 1;//intval(date('d'));
    // What is the first day of the month in question?
    $hariPertama /*:unix timestamp*/ = mktime(0, 0, 0, $month, 1, $year);

    // How many days does this month contain?
    $numberDaysOfMonth = intval(date('t', $hariPertama));
    $rem = $numberDaysOfMonth - $curDay;
    // Retrieve some information about the first day of the
    // month in question.
    $dateComponents = getdate($hariPertama);

    // What is the name of the month in question?
    $monthName = $dateComponents['month'];

    // What is the index value (0-6) of the first day of the
    // month in question.
    $dayOfWeek = $dateComponents['wday'];

    // Create the table tag opener and day headers

    $calendar = "<table class='calendar'>";
    $calendar .= "<caption>$monthName $year</caption>";
    $calendar .= "<tr>";

    // Create the calendar headers

    foreach ($daysOfWeek as $day) {
        $calendar .= "<th class='header' style='text-align: center;'>$day</th>";
    }

    // Create the rest of the calendar

    // Initiate the day counter, starting with the 1st.

    $currentDay = $curDay;

    $calendar .= "</tr><tr>";

    // The variable $dayOfWeek is used to
    // ensure that the calendar
    // display consists of exactly 7 columns.

    if ($dayOfWeek > 0) {
        $calendar .= "<td colspan='$dayOfWeek'> </td>";
    }

    $month = str_pad($month, 2, "0", STR_PAD_LEFT);
    $conn = get_connection();
    if (!$conn) die(500);
    $query = $conn->query("SELECT * FROM progress");
    $dates = [];
    while ($row = $query->fetch_assoc()) { //ERROR

        $d = date('d', $row["tanggal"]);
        $dates[$d] = $row["status"];
    }
    while ($currentDay <= $numberDaysOfMonth) {

        // Seventh column (Saturday) reached. Start a new row.

        if ($dayOfWeek == 7) {

            $dayOfWeek = 0;
            $calendar .= "</tr><tr>";

        }

        $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);

        $date = "$year-$month-$currentDayRel";
        $color = "";
        if (array_key_exists($currentDay, $dates)) {
            if ($dates[$currentDay] == 1) $color = "background: green";
            elseif ($dates[$currentDay] == 2) $color = "background: red";
        }
        $tanggal = mktime(null, null, null, $month, $currentDay, $year);
        $calendar .= "<td class='$date' style='text-align: center; $color' >$currentDay<br>
            <button type=\"button\" class=\"btn\" data-toggle=\"modal\" data-target=\"#myModal\" data-tanggal='$tanggal'>SHORT JUMP</button>
            <button type=\"button\" class=\"btn\" data-toggle=\"modal\" data-target=\"#myModal\" data-tanggal='$tanggal'>NO SMOKE</button>
        </td>";

        // Increment counters

        $currentDay++;
        $dayOfWeek++;

    }

    // Complete the row of the last week in month, if necessary

    if ($dayOfWeek != 7) {

        $remainingDays = 7 - $dayOfWeek;
        $calendar .= "<td colspan='$remainingDays'> </td>";

    }

    $calendar .= "</tr>";

    $calendar .= "</table>";

    return $calendar;

}
[/insert_php]
[insert_php]
$curMonth = date('n');
$curYear = date('Y');
echo kalender($curMonth, $curYear, 60);
[/insert_php]

itu sudah saya masukin code nya

avatar gbagoes
@gbagoes

3 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban