My code executes but only for the most recent row stored in the database. It doesn't check through the other rows and keeps executing on the same data in the recent row. What function am I missing?
Adding while(true) condition, which now loops but only loops the most recent.
$db = mysqli_connect("" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"ds_main") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
} else {
/*SUCCESS MSG*/
echo '';
}
$sqlCommand = "SELECT companyname, domainurl, expirationdate FROM domains WHERE expirationdate BETWEEN CURDATE() AND CURDATE()+INTERVAL 30 DAY";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
//fetch the data from the database
$domainnames = "domainurl";
$domaindate = "expirationdate";
while ($row = mysqli_fetch_array($query)) {
$domainnames = $row['domainurl']; // list of expiring URLs
$domaindate = $row['expirationdate']; // list of expiry dates
} // that's it for the loop
if (count($domainnames) > 0 ) {
//carrys out a task
}
// Free the results
mysqli_free_result($query);
//close the connection
mysqli_close($db);
}
?>
I expect the code to execute across all rows, not just the most recent. I'm new to php.