php - Obtain record from MySQL strip tags then update -
i have field (description) in mysql database (poi). wish use php , strip_tags remove html records in database. want update result same description field in database.
i have no problem obtain string , stripping html, can't seem work out how update database result.
// check connection if(mysqli_connect_errno()) { echo "connection failed: " . mysqli_connect_errno(); exit(); } $sql_article = "select description poi"; $result = $mysqli->query($sql_article); // iterates through mysql results while ($row = $result->fetch_array()) { $description_no_html = strip_tags($row['description']); printf("%s<br />\n", $description_no_html); }
ideally each row have unique id column can use specify row update using prepared statement:
$sql_article = "select id, description poi"; $result = $mysqli->query($sql_article); $stmt = $mysqli->prepare("update poi set description = ? id = ?"); // iterates through mysql results while ($row = $result->fetch_array()) { $description_no_html = strip_tags($row['description']); printf("%s<br />\n", $description_no_html); $stmt->bind_param("si",$description_no_html,$row['id']); $stmt->execute(); }
if don't have unique id column, use following statement instead
$stmt = $mysqli->prepare("update poi set description = ? description = ?");
and
$stmt->bind_param("ss",$description_no_html,$row['description']);
alternative: stripping tags directly in mysql
you can create custom mysql function strips tags (https://stackoverflow.com/a/13346684/3574819) , use following query
update poi set description = strip_tags(description)
disclaimer: i'm not sure how above referenced mysql strip_tags
works, mileage may vary depending on content.
Comments
Post a Comment