I have been trying to figure this out and have been scouring Stackoverflow and other sites for anything related to my problem.
I have a php script that is updating a mysql table as people open the respective page. The whole thing works fine (as I have been having it print text each step of the way to verify that the data is there. The update is placing either the url and other data into the table if the page has never been visited or updating the total_votes and current_vote per visit. The total_votes is for a statistical reporting used on a different page. The current_vote diminishes in value each week.
For some reason I am getting a Warning. I figure that it is better to ask despite the whole thing working as I hate Warnings and errors that I can't resolve (even if there is no problems with the end result.
The database is set to utf8_general_ci so the url information shouldn't be an issue on that end.
Here is the chunk of code that I have for this section (the Warning is on while ($row = mysqli_fetch_array($query)){
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$cururl = curPageURL();
echo $cururl;
require_once "scripts/connect.php";
$sqlCommand = "SELECT Count(*) as `Counter` FROM `hot_topics` WHERE `article_url` = '". $cururl ."'";
$query = mysqli_query($myconnection,$sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)){
$Count = $row["Counter"];
echo $Count;
if ($Count == 1) {
echo '1';
require_once "scripts/connect.php";
$sqlCommand = "UPDATE `hot_topics` SET `total_votes` = `total_votes`+1, `current_vote` = `current_vote`+1 WHERE `article_url` = '". $cururl ."'";
$query = mysqli_query($myconnection,$sqlCommand) or die (mysqli_error());
} elseif ($Count == '0') {
echo '2';
$yearHead=$_GET["yearrange"];
$weekHead=$_GET["weekrange"];
if ($weekHead == 'Current') {
$type=$_GET["type"];
$yearHead = date("Y");
$weekHead = date("W");
$Startdate = new DateTime();
$Startdate->setISODate($yearHead, $weekHead);
$Enddate = new DateTime();
$Enddate->setISODate($yearHead, $weekHead, 7);
require_once "scripts/connect.php";
$sqlCommand = "INSERT INTO `hot_topics` (`total_votes`, `current_vote`, `article_url`, `article_title`) VALUES ('1', '1', '". $cururl ."', '". $type ." Chart: ". $Startdate->format('d/F/Y') ." - ". $Enddate->format('d/F/Y') ."')";
$query = mysqli_query($myconnection,$sqlCommand) or die (mysqli_error());
} elseif ($weekHead == 'All') {
$type=$_GET["type"];
require_once "scripts/connect.php";
$sqlCommand = "INSERT INTO `hot_topics` (`total_votes`, `current_vote`, `article_url`, `article_title`) VALUES ('1', '1', '". $cururl ."', '". $type ." Chart: All Weeks')";
$query = mysqli_query($myconnection,$sqlCommand) or die (mysqli_error());
} else {
$type=$_GET["type"];
$yearHead=$_GET["yearrange"];
$weekHead=$_GET["weekrange"];
echo $yearHead;
echo $weekHead;
$Startdate = new DateTime();
$Startdate->setISODate($yearHead, $weekHead);
$Enddate = new DateTime();
$Enddate->setISODate($yearHead, $weekHead, 7);
require_once "scripts/connect.php";
$sqlCommand = "INSERT INTO `hot_topics` (`total_votes`, `current_vote`, `article_url`, `article_title`) VALUES ('1', '1', '". $cururl ."', '". $type ." Chart: ". $Startdate->format('d/F/Y') ." - ". $Enddate->format('d/F/Y') ."')";
$query = mysqli_query($myconnection,$sqlCommand) or die (mysqli_error());
}
}
}
?>
The warning that I have been getting is: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in...