<?php
$servername = "localhost";
$username = "eklavya_eklavya";
$password = "eklavya?0419*";
$database = "eklavya_eklavya";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
//die();
$intCatID = 675;
$sql = "SELECT id, alias from j4_categories WHERE parent_id = 51 AND id = ".$intCatID;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$parentCatAlias = $row['alias'];
$arrParentCat = implode("-", $row);
$arrParentCatID = $row['id'];
}
} else {
echo "No records found 1";
}
//echo "<pre>"; print_r($arrParentCat); echo "</pre>";
$sql = "SELECT id, alias from j4_categories WHERE parent_id = ".$arrParentCatID;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$arrArticleCatAlias = $row['alias'];
$arrArticleCat = implode("-", $row);
$arrArticleCatID = $row['id'];
$oldVal = "/".$arrArticleCatID."-".$parentCatAlias."/".$arrArticleCatAlias."/";
$NewVal = "/".$arrParentCat."/".$arrArticleCat."/";
//echo "<br><br><br>";
echo "<br>";
echo $updateSql = "UPDATE j4_categories set description = REPLACE(description , '$oldVal', '$NewVal')
WHERE description LIKE ('%$oldVal%') AND parent_id = ".$intCatID;
//die();
echo "<br><br>";
if ($conn->query($updateSql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
}
} else {
echo "No records found 2";
}
$conn->close();
?>