簡體   English   中英

有沒有一種方法可以在所有行上執行,而不僅僅是最近的?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM