function udpate_database($value = '', $type = '', $id) { echo "<br>[process]:update database process started<br>"; include "getpath.php"; $targetdir = $localhost . "Matching-Game/assets/" . $type . "/"; $srno = getsrno($value); include $localhost . 'Matching-Game/assets/getconfig.php'; $conn = new mysqli("localhost", $sqlun, $sqlp, $sqld); if ($conn->connect_error) { die("Connection Failed:" . $conn->connect_error . "::;;error!"); } $query = "SELECT * from pairs where id>{$id} "; $result = $conn->query($query); while ($row = mysqli_fetch_row($result)) { if ($row[1] == $type) { $ext = getextension($row[0]); rename($targetdir . $row[0], $targetdir . $type . $srno . "." . $ext); $query = "UPDATE pairs SET c1name='{$type}{$srno}.{$ext}' WHERE c1name='{$row['0']}'"; $res = $conn->query($query); echo "<br>[process]:{$row['0']} renamed to {$type}{$srno}.{$ext}<br>"; $srno++; } if ($row[3] == $type) { $ext = getextension($row[2]); rename($targetdir . $row[2], $targetdir . $type . $srno . "." . $ext); $query = "UPDATE pairs SET c2name='{$type}{$srno}.{$ext}' WHERE c2name='{$row['2']}'"; $res = $conn->query($query); echo "<br>[process]:{$row['2']} renamed to {$type}{$srno}.{$ext}<br>"; $srno++; } } }
function getfilename($type) { include "getpath.php"; include $localhost . 'Matching-Game/assets/getconfig.php'; $conn = new mysqli("localhost", $sqlun, $sqlp, $sqld); if ($conn->connect_error) { die("Connection Failed:" . $conn->connect_error); } $query1 = "select c1name as name,id from pairs where c1type='" . $type . "' order by id desc limit 1 "; $result1 = $conn->query($query1); $query2 = "select c2name as name,id from pairs where c2type='" . $type . "' order by id desc limit 1 "; $result2 = $conn->query($query2); if ($result1 && $result2) { $data1 = $result1->fetch_assoc(); $data2 = $result2->fetch_assoc(); $data1 = $data1['name']; $data2 = $data2['name']; $srno1 = getsrno($data1); $srno2 = getsrno($data2); if ($srno1 > $srno2) { return $type . ($srno1 + 1); } else { return $type . ($srno2 + 1); } } }