I am trying to update multiple values from same column with an array of multiple values, but I am not getting exactly why the values from the same column are updated with only one value from the array.
PHP
$subscribers = $db->query('SELECT * FROM subscribers');
while ($subscriber = $subscribers->fetch_object()) {
$email = $subscriber->email;
}
$pagerank_update = $db->query('SELECT * FROM pagerank_update');
$url_pr = array('1','2','3','4');
foreach ($url_pr as $url_pr_value) {
while ($website = $pagerank_update->fetch_object()) {
$url = $website->URL; //domain1.com...
$pagerank = $website->CURRENT_PR; // 0
$date = $website->PR_TODAY; // 0
$id = $website->ID;
//$url_pr = getpr($url);
//var_dump($url);
//if ($url_pr_value !== $pagerank) {
$db->query("UPDATE pagerank_update SET PR_TODAY = '$url_pr_value' WHERE URL = '$url'");
$var = "UPDATE pagerank_update SET PR_TODAY = '$url_pr_value' WHERE URL = '$url'";
var_dump($var);
//} else {}
}
}
The var_dump looks in English like this:
UPDATE pagerank_update SET PR_TODAY = '1' WHERE URL = 'http://domain1.com'
UPDATE pagerank_update SET PR_TODAY = '1' WHERE URL = 'http://domain2.com'
UPDATE pagerank_update SET PR_TODAY = '1' WHERE URL = 'http://domain3.com'
UPDATE pagerank_update SET PR_TODAY = '1' WHERE URL = 'http://domain4.com'
EXPECTED OUTPUT would be
UPDATE pagerank_update SET PR_TODAY = '1' WHERE URL = 'http://domain1.com'
UPDATE pagerank_update SET PR_TODAY = '2' WHERE URL = 'http://domain2.com'
UPDATE pagerank_update SET PR_TODAY = '3' WHERE URL = 'http://domain3.com'
UPDATE pagerank_update SET PR_TODAY = '4' WHERE URL = 'http://domain4.com'
Where am I mistaking?
$url_pr_value = 1;then in the data fetch loop use the update command and then do$url_pr_value++this should solve the problem.$url_pr_value++, that is for testing purposes, I am trying to assign different values to each urls. Function getpr() that is commented that is the function that should get different value for each url. The script is about getting the pagerank of each url and updating it as follows.