Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:45:54+00:00 2026-06-02T02:45:54+00:00

I already have data I scraped from a web table and I’ve noticed some

  • 0

I already have data I scraped from a web table and I’ve noticed some leading spaces and nbsp in some entries. I realize I should have cleaned the data while scraping before inserting it into MySQL but it was a while ago and I don’t feel like repeating the process if I don’t have to. I came up with this PHP script (late) last night and it works up until I try to update the entries.

<?php
require_once("login.php");

$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database);

$query = "SELECT * FROM ingredients;";

$result = mysql_query($query);
$i = 1;
$e = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    //echo $row[1];
    $str = trim(mysql_real_escape_string($row[1]));
    $e[] = $str;
    $i++;

}

//print_r($e);
/*
$i = 1;
foreach($e as $entry) {
    $query = "UPDATE ingredients
        SET ing_name = $entry
        WHERE ing_id = $i;";
    mysql_query($query);
    $i++;
}*/
?>

Couple of questions:

  1. Is there a way to do this strictly in MySQL without using PHP?
  2. What function/s should I use to strip the strings in order to convert to plaintext and remove all leading, trailing, and nbsp spaces?
  3. The PHP script seems to work until updating the data, what gives?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:45:56+00:00Added an answer on June 2, 2026 at 2:45 am

    There’s a large number of MySQL String Functions that can help with this sort of thing.

    You might need a combination of REPLACE and TRIM to clean it up:

    UPDATE table SET column=TRIM(REPLACE(column, '&nbsp;', ' '))
    

    Also try not to use mysql_query, but use PDO instead. Writing queries directly leaves you exposed to SQL injection problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data table which already has some values, plus it is getting
I already have Java code to display and process data from a database. I
I have already created a webpart to show the data from list, but I
I have data from a CSV file that's already loaded into memory. So I
I have a python function that scrapes some data from a few different websites
I already have binary data read from a file. Most of the examples I
I already have some output from a jQuery function, say: users => 1, 2,
If I already have the wav data in two arrays (left channel & right
If i already have record with the exact same data in mysql database i
i have already finished code to passing data to url , and it did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.