I have a mySQL table PRERENDER like this
id | canonical | prerender | count
------------------------------------------------
01 | example.com/1 | Example.com/23 | 12
02 | example.com/1 | Example.com/54 | 10
03 | example.com/2 | Example.com/5 | 12
...
canonical + prerender are an index, the couple can't be duplicated. if the couple already exists so add +1 to count
What I need:
I need to get
when active URL = $canonical get the prerender field with the highest counter.
this is what I try:
$canonical="https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$sql2 = mysql_query('
SELECT prerender
FROM PRERENDER
WHERE (canonical = '.$canonical.') AND (count = MAX(count))
';
Any tips?
CODE UPDATE
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
$referral=$_SERVER['HTTP_REFERER'];
$referral = strtok($referral, '?');
$canonical="https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if ((strpos($referral, 'evemilano.com') !== false)) {
$sql = "INSERT IGNORE INTO PRERENDER (ID,canonical,prerender,count) VALUES (NULL,'$referral','$canonical','1') ON DUPLICATE KEY UPDATE count = count +1 ";
}
if (!mysqli_query($conn, $sql)) { printf("Errormessage: %s
", mysqli_error($conn));}
$sql2 = "SELECT prerender FROM PRERENDER WHERE canonical = '$canonical' ORDER BY count desc limit 1";
echo 'pre: ';
$result= mysqli_query($conn, $sql2);
foreach($result as $row)
{
echo $row['prerender'];
}
UPDATE: now it works