Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "127.0.0.1";
- $username = "root";
- $password = "root";
- $dbname = "mv_dev";
- $source_field = "question";
- $table = "mv_ask";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id,".$source_field." FROM ".$table;
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo $row[$source_field]."\n";
- $route = trim(preg_replace("/[^A-Za-z0-9 ]/", '', $row[$source_field]));
- $route = str_replace(" ","-",$route);
- $route = strtolower($route);
- $route = substr($route, 0, 100);
- echo $route."\n\n";
- // Update the record
- $sql2 = "UPDATE $table SET route='".$route."' WHERE id=".$row["id"];
- if ($conn->query($sql2) === TRUE) {
- echo "Record updated successfully\n\n";
- } else {
- echo "Error updating record: " . $conn->error;
- }
- }
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
Add Comment
Please, Sign In to add comment