You need to collect the email addresses from your database and iterate over your results. Also mail() is the least verbose; I would advise using PEAR or another SMTP library.
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT email FROM table")) {
    printf("<p>Select returned %d rows.</p>\r\n", $result->num_rows);
    echo "<ul>\r\n";
    while($row = $result->fetch_assoc()){
        if(mail($row['email'], 'My Spam Subject', 'My Spam Email')){
            echo "<li>Spam sent to {$row['email']}</li>\r\n";
        } else {
            echo "<li>Mail failed.</li>\r\n";
        }
    }
    echo "</ul>\r\n";
    /* free result set */
    $result->close();
}
$mysqli->close();
?>