Jump to content

Recommended Posts

Hi guys i need to replace some data in one of my queries i think the best way to do this is through 3 str_replace queries but im not sure where to place this within by script.

 

Can anyone help me with this?

 

$arr = array();
$query = "SELECT * FROM errordata WHERE MerchantID = 'Dial-A-Phone'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
     while($row = mysql_fetch_array($result)) $arr[$row['error_text']] = $row['correct_id'];
} else {
   echo 'No rows found!';
}

 

Thanks, Phil

Link to comment
https://forums.phpfreaks.com/topic/161343-need-to-replace-data/
Share on other sites

Most likely here:

 

$arr[$row['error_text']] = $row['correct_id'];

 

You'll want to replace the data stored within $row['correct_id'] before storing within your array - though I'm totally guessing as you've not supplied much information as to what you're trying to replace.

 

However, as there's no braces {} after the while loop you can only run one statement, which depending how you've done the str_replace()'s may cause a problem. Change it to this to avoid any confusion:

 

     while($row = mysql_fetch_array($result)) {
        $arr[$row['error_text']] = $row['correct_id'];
     }

Link to comment
https://forums.phpfreaks.com/topic/161343-need-to-replace-data/#findComment-851415
Share on other sites

Hmm maybe im going about it the wrong way.

 

I have a number of text strings which have double spaces. In the database the string is displayed like this

 

"text  12"

 

but when the browser receives the text it looks like this

 

"text 12"

 

How can i get it so that the extra space is still present?

 

Thanks again

Phil

Link to comment
https://forums.phpfreaks.com/topic/161343-need-to-replace-data/#findComment-851419
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.