Pstivala7
Pstivala7

Reputation: 25

I need to remove some characters from a SQL field without altering database

I am using a database that was already created and I can access, but do not have the permission to alter the database at all.

I am using the query

select last_count, query, job_id from twitterinblack46.job where job_id in ('.$job_id_all.') order by last_count desc; 

to call three columns (last_count, query, and job_id) and display them in a table.

This query works as I want it to, but the only issue is the query column displays data with either a "%23","%40","%20", or "q=" in front of the desired data.

I need to figure out how to get rid of these strings before displaying the table.

Here is the while statement used to generate the table:

while($row = mysql_fetch_array($result)){
    echo"<tr>";
    echo "<td>" . $row["job_id"] . "</td>";
    echo "<td>" . $row["last_count"] . "</td>";
    echo "<td>" . $row['query'] . "</td>";
    echo "<tr>";
}

echo "</table>";

I have created this query:

select replace(replace(replace(REPLACE(query,'%23', ''),'%40',''),'q=',''),'%20','') from job; 

to get rid of these characters and it works perfectly as I need it, but how can I incorporate this query into my other $result before creating the table?

Upvotes: 0

Views: 585

Answers (2)

Stefan
Stefan

Reputation: 3900

$lst_search = array("%23", "%40", "%20", "q=");
$query = str_replace($lst_search, "", $row["query"]);

Then use $query in place of $row["query"] when creating the table.

Upvotes: 1

webbiedave
webbiedave

Reputation: 48887

You can remove the offending strings when printing the table:

echo "<td>" . str_replace(array('%23', '%40', '%20"', 'q='), '', $row['query']) . "</td>";

(If you want to limit removal to only characters at the beginning of the string you can look at preg_replace)

Upvotes: 1

Related Questions