Jump to content

Archived

This topic is now archived and is closed to further replies.

yammez

SELECT query is not pulling full value from table

Recommended Posts

I'm banging my head against the wall on this one. I have an MSSQL database which stores information from an online form. I also have a PHP script that pulls information from this database, one record at a time, to display on a .php page.

 

Four of the columns, that are set to VARCHAR(2000), contain values that are about 1000 characters long. These values come from a <textarea> field on a separate form. When I view the table in SQL Server Management Studio Express, I can see the full 1000 character values. Because of this, I know the insert query is working properly.

 

The problem comes when I try to echo these values in the PHP script, it only echoes 250 characters. What would prevent this from echoing the full 1000 characters?

 

Some things that I've tried, none of which work:

- I've tried to echo the value with the nl2br() function.

- I've tried print instead of echo. (if there is even a difference anymore)

- I've tried making a separate query string and result set that only fetches one of the 1000-character values, and echoing that.

- I've checked my code on the W3C validator; it IS valid.

- I've tried different settings for the <textarea>'s "wrap" attribute.

- I've changed the html tags around the echoed value to <p>, <pre>, <span> etc.

- I've made sure the CSS is not affecting these tags by not linking it.

 

Here's a sample of my code:

The textarea:
<textarea name="question22" rows="4" cols="50" wrap="hard"></textarea>

The query:
$query = "SELECT * FROM dbo.academic_success_assessments WHERE assessment_id = '$assessment_id'";
$result = mssql_query($query);
$row = mssql_fetch_array($result,MSSQL_ASSOC);

The display:
echo "<p>".$row['question20'].</p>";

Share this post


Link to post
Share on other sites

Have you done a "view source" of the page in your browser to see if all the content is actually present?

 

All content that could contain any HTML special characters (<, >, ', ") must be passed through the htmlentities function to insure that any HTML special characters in it don't break the HTML on your page.

Share this post


Link to post
Share on other sites

Ah, my mistake, I'll edit my first post to reflect this. When the value from the form is inserting into the database, I do run it through the htmlentities() function. Also, I have looked at the source, at it only displays the first 250 characters there too.

 

Edit: I just realized I cannot edit my initial post :(

 

I should also note that there are also only alpha characters (no apostrophes, commas, even periods) in the text that I'm entering. I'm just entering something along the lines of:

sdjfh ashflkjasdhfkasj hdfkasl ksajdfh akshf khsafl hsaldkjfh sldkjfh aslkj
sakdj fhkjlashf kjhf lkjsdhafk jsdhfk jlhsdk jhaslk fjhsladkj fhksj fhkja
skdjfhka jhksjad hkj hkjsfh kjshakflsjd hdklsja fhkljshf kjshadk fjhskl f

Share this post


Link to post
Share on other sites

Can you post the values of the setup of the relevant field? For example, is there a limit value imposed on the SQL field? This might happen with a varchar type field.

Share this post


Link to post
Share on other sites

are you using the mssql.dll for your connections?

 

There was a bug with select statements that limited return to 256 characters with that .dll - What setup do you have? If windows try using the sqlsrv.dll instead. It's got a different API which is a pain, but it apparently resolves a lot of flaws that the mssql.dll has.

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&displaylang=en

Share this post


Link to post
Share on other sites

That's a good suggestion, I'll have a chat with the server admin to find out.

Share this post


Link to post
Share on other sites

After a chat with the server admin, he told me he would look into it and call me later (he had heard of the .dll bug). Well, he called me later and told me to change the VARCHARs to TEXTs. Works like a charm :)

Share this post


Link to post
Share on other sites

×
×
  • 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.