我的代码仅对数据库中存储的最新行执行。它不会检查其他行,并继续对最近一行中的相同数据执行。我缺少什么功能?
添加while(true)条件,该条件现在会循环,但只会循环最新的条件。
$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);
}
?>
我希望代码可以跨所有行执行,而不仅仅是最新行。我是php的新手。
答案 0 :(得分:1)
您的代码在所有行上都“执行”,但是在每一行上,它用最新行的值覆盖hackuta/urls.py
和$domainnames
的值。我怀疑您可能打算建立一系列域名和日期,更像是这样:
$domaindate