Example #1
0
function write_result_to_csv($filepath, $result)
{
    $data = get_result_as_arrays($result);
    if (!($handle = fopen($filepath, 'w'))) {
        return false;
    } else {
        foreach ($data as $row) {
            fputcsv($handle, $row);
        }
        fclose($handle);
    }
    return true;
}
Example #2
0
    get_template_part('content', 'page');
    ?>
				<?php 
    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn) {
        echo "Connection failed: " . mysqli_connect_error();
    }
    $sql = "SELECT `First Name`,`Last Name`,`identifier` FROM `student_list` WHERE Grade='Graduated' ORDER BY `Last Name`";
    $result = mysqli_query($conn, $sql);
    if (!$result) {
        echo "<p style=\"color: red;margin: 20px\">There was an error retrieving the data. Please try again.</p>";
        $data = null;
    } else {
        $data = get_result_as_arrays($result);
    }
    ?>
				<table>
					<?php 
    $num_cols = 4;
    for ($person = 0; $person < count($data); $person++) {
        if ($person % $num_cols == 0 || $person == 0) {
            echo "<tr>";
        }
        echo '<td style="text-align: center">';
        if (file_exists(ABSPATH . 'student_pictures/' . $data[$person][0] . '-' . $data[$person][1] . '-' . $data[$person][2] . '.jpeg')) {
            echo '<img src="' . site_url() . '/student_pictures/' . $data[$person][0] . '-' . $data[$person][1] . '-' . $data[$person][2] . '.jpeg"' . ' style="width: 150px;height: auto"><br>';
        }
        echo $data[$person][0];
        echo "<br>";