[英]Is there a way of executing on all rows not just the most recent?
我的代码执行但仅针对存储在数据库中的最新行。 它不会检查其他行并继续对最近行中的相同数据执行。 我错过了什么 function?
添加 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 的新手。
您的代码在所有行上“执行”,但在每一行上,它都用最新行的值覆盖$domainnames
和$domaindate
的值。 我怀疑您可能打算构建一个域名和日期数组,更像这样:
$domainnames = array(); // list of expiring URLs
$domaindate = array(); // list of expiry dates
while ($row = mysqli_fetch_array($query)) {
$domainnames[] = $row['domainurl']; // add to list
$domaindate[] = $row['expirationdate']; // add to list
} // that's it for the loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.