<?php
error_reporting(0);
include("../../config/database.php");
$name = $_GET['name'];
$tableName = $_GET['tableName'];
if(!empty($name))
{
$slug = preg_replace("/-$/","",preg_replace('/[^a-z0-9]+/i', "-", strtolower($name)));
$query = "SELECT COUNT(*) AS NumHits FROM $tableName WHERE slug_url LIKE '$slug%'";
$result = mysqli_query($cn, $query);
$row = mysqli_fetch_array($result);
$numHits = $row['NumHits'];
echo ($numHits > 0) ? ($slug . '-' . $numHits) : $slug;
}
?>