User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,083 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,962 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1622 | Replies: 5 | Solved
Reply
Join Date: Feb 2007
Posts: 4
Reputation: joezyz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joezyz joezyz is offline Offline
Newbie Poster

Help mssql_fetch_array or mssql_query is stripping out a space in PHP

  #1  
Feb 22nd, 2007
Hello everyone,

I have a MSSQL db with PHP front end.
The data in the table is similiar to:

"Two spaces" with 2 white spaces in the middle.

When I use this code:
  $sql = "select Name FROM Name_TBL  WHERE Number = '$Num";
  $rs = mssql_query($sql);
   $RT = mssql_fetch_array($rs);
     $Name= $RT[Name'];

In the DB, and when I use another query analyzer, I get the correct return of "Two spaces" with 2 white spaces in the middle.

BUT...in PHP when I echo $Name, one of the two spaces has been deleted.
So I echo "Two spaces" with 1 white spaces in the middle.
I need the varchar to be exactly like it is in the DB, and I CANNOT change the data to one space.

Does anyone know what is causing this? Is there someting in the php.ini file that would do this?

PLEASE HELP I AM STUCK!!

-Joe
Last edited by joezyz : Feb 22nd, 2007 at 4:15 pm. Reason: spellin and clarificaiton
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 37
Reputation: jblacdao is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
jblacdao jblacdao is offline Offline
Light Poster

Re: mssql_fetch_array or mssql_query is stripping out a space in PHP

  #2  
Feb 22nd, 2007
Hi joe,

There isn't any problem at all because PHP really outputs series of spaces as just one. I suggest that you either configure the script that inserts the records in the database to automatically converts series of spaces to just one or explode your string to an array such that 1 character string = 1 array element and out each element separately. Hope this helps.
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: mssql_fetch_array or mssql_query is stripping out a space in PHP

  #3  
Feb 23rd, 2007
Another option is to pre-format the string using substring_replace($string, $replacement) before posting to the DB, where the replacement should be  
In this way you will have the string pre-formated inside the DB, so the echo will come out with   and you'll have the 2 psaces.
Reply With Quote  
Join Date: Feb 2007
Posts: 4
Reputation: joezyz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joezyz joezyz is offline Offline
Newbie Poster

Re: mssql_fetch_array or mssql_query is stripping out a space in PHP

  #4  
Feb 23rd, 2007
Thanks everyone, but the Data in the Database CANNOT be changed.

The job of any database extension is the display the data EXACTLY as it is written in the DB. It should not re-write the data based on arbitrary rules.

This page is dynamic. Some of the data returned has one space, this one record has two. I cannot make a rule that changes all of the dat to 2 spaces.

The actual data has 4 parts, each separated by a space, and one, separated by 2 spaces. (on this record only). The other records have 1 space.

The explode does not work, because I need to reconstruct the name, and I cannot do this dynamically, because programatically, the computer does not know where the 2 spaces will go.

Does anyone know if there is another way to get the data other than mssql_fetch_* (row, array, etc) from a MSSQL DB that will NOT change the data from what is written in the DB?

Thanks!!!
Please keep the suggestions comming.
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: mssql_fetch_array or mssql_query is stripping out a space in PHP

  #5  
Feb 23rd, 2007
Normally both PHP and HTML are ignoring multiple spaces and display them as one single space.

If you're sure you get the correct data from the database, trya simple test over the result.
[php]
$name = str_replace (' ', ':', RT['yourresult here']);
echo $name;
[/php]
If you receive the data correctly from the DB, your spaces should be replaced by columns. So if you have returned 2 spaces from the DB, you should see a result like this

value1::value2

Then, if you get the correct result, run the same function but like this:
str_replace(' ', ' ', rt['your result here']);

NOTE THAT THERE IS A SPACE BETWEEN THE FIRST QUOTES
Last edited by Rhyan : Feb 23rd, 2007 at 10:32 am. Reason: addding more detail
Reply With Quote  
Join Date: Feb 2007
Posts: 4
Reputation: joezyz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joezyz joezyz is offline Offline
Newbie Poster

Re: mssql_fetch_array or mssql_query is stripping out a space in PHP

  #6  
Feb 23rd, 2007
YOU ARE THE BEST!!! That works perfectly!!!!

Thank you so much. I have been pounding my head on this one. I never thought to use the &nbsp. I kept trying to replace it with spaces, and got the same result.

THANKS!!!!

-Joe
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC