Morning,

I have a field in my SQL database varchar 8000 for a text field. When I display it on the edit form only 255 char show up even though there are more than that in the database field and running the backend query shows the correct information.

Is there a way I can make it show all and not just the default 255 chars? Below is a snippet of the code:

/* construct and run our query */
$result = mssql_query("select * from dbo.vwIncidentReport where IncidentID = '$IncidentID'");
$myrow = mssql_fetch_array($result);

Details of Investigation:<textarea name="DetailsOfInvestigation" cols="60" rows="12"><?echo $myrow["DetailsOfInvestigation"] ; ?></textarea>

Any thoughts would be most welcome. Thanks.

Laura

    You most probably cannot have a VARCHAR(8000) field, perhaps a max of VARCHAR(255)
    Use a TEXT or BLOB field instead.

      Thansk for that. The database is holding the records correctly the problem I am having is that the PHP only DISPLAYS 255 characters no matter how many characters are in the database field.

      I'm very confused. No where did I say limit the results.

        Check the actual values in the database - I could be wrong, but I believe that VarChar fields are limited in MySQL to 255 characters, then they truncate the remainder. So it doesn't sound like it's PHP, but MySQL. As laserlight suggested, switch the field type to text and it should be good to go.

        edit OK, I need to read posts more carefully before posting. Sorry 'bout that... However, I think swapping the type to Text as laserlight suggested will in fact do the trick. end edit

          The database is holding the records correctly the problem I am having is that the PHP only DISPLAYS 255 characters no matter how many characters are in the database field.

          hmm... okay, it appears that the max for VARCHAR on your DBMS is indeed 8000, so that shouldnt be a problem. Do you have the problem when you print the string directly, instead of displaying in a form control?

            lmayer, laserlight is correct. If you check the mysql documentation you will find out that the maximum size of a varchar is 255 characters (check here here). Refactor your DB scema such that the field is a TEXT (or BLO😎 as laserlight says.

              Thanks for all the help. I did change it to a text field and now it displays correctly. Very strange, I wonder why it wont take varchar 8000 it would only take text.

              Thanks again.

              Laura

                Depending on your version, it's perhaps because MySQL says so:

                Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.

                  Depending on your version, it's perhaps because MySQL says so:

                  The thing is, Laura's code uses the mssql functions, and a quick search of the Web showed me that 8000 was the max for that DBMS with VARCHAR.

                    Ooh, you're right. Yeesh, I get so used to everyone else using MySQL that I miss it when someone doesn't use MySQL. MyBAD.

                    Looking around, I found a page on the subject here. So varchar(8000) was introduced in SQL Server 7.0, and prior to that the limit was 255. PHP's page on [man]mssql[/man] notes that it uses Microsoft's library written for version 6 - which still had a 255-character limit on varchars.

                    So that's where the truncation is happening. (Incidentally, afterwards I tried searching that [man]mssql[/man] manual page for "8000" and found exactly this description.)

                      Thanks for all the help.

                      Laura

                        Write a Reply...