Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot display entire field contents from DB.

Status
Not open for further replies.

seahorse123

Programmer
Jul 25, 2005
39
0
0
US
I have text contents that is saved in the table column "message varchar 5000"
However when I tried to retrieve it, it only display the first 255 characters:
Code:
$query="select message from tb1 where id=1";
$result=mssql_query($query);
for ($i=0;$i < mssql_num_rows($result); ++$i)
{
$line=mssql_fetch_row($result);
$message=$line[0];
print "$message";
}

I don't why it only displays the part of text, anyone can help me? thanks.
 
If you were running the query in query analyzer then you can update the Maximum Characters Per Column option under Tools/Options/Results Pane, but not really sure how to set that at connection level. Try that and see what you get.

Regards,
AA
 
What is $message declared as? Have you tried printing
"print $line[0];" to see what it returns?


"I'm living so far beyond my income that we may almost be said to be living apart
 
Yes, I tried "print $line[0];", it still cut the text to around 255 characters.

Any idea?
 
1. are you sure the column is set for a length of 5000?

2. what are you using as a front-end, could that be where the data is being shortened?

-SQLBill

Posting advice: FAQ481-4875
 
I use Microsoft SQL server Enterprise Manager to build the table.
1) Yes, I have set the column "message varchar 5000".
2) If I directly go to "SQL server Enterprise Manager-->Console Root-->SQL server group-->tables", and open table, I can see the column "message" has more contents(though I'm not sure it's around 5000, but at least much large than 255 characters)

The weird thing is when I use SELECT statement, it just cuts around 255 characters.

 
Ahhh...that explains it....

I've seen somewhere else that Enterprise Manager only shows 255 characters, no matter what.

-SQLBill

Posting advice: FAQ481-4875
 
So what is the solution to display text that has 255 or more characters?
As the data is alreay stored in the table, only issue is how to display that column.

 
amrita418 has the answer in a previous post.. there are settings in QA
 
I would use a front-end that is designed to do queries (Enterprise Manager, while it CAN do queries, is really to MANAGE SQL Server). As jbenson001 says, use Query Analyzer. Either get to it via Start>Programs or in Enterprise Manager, highlight your database, click on Tools in the menu bar, and select Query Analyzer.

-SQLBill

Posting advice: FAQ481-4875
 
Extract the data contents to a file, you can do this by right clicking on the table and exporting the data to a flat file. I believe you should be able to punch in your SQL query to select specific data so you do not have to weed through all the records in the table to find the one you are looking for...

ASP, VB, VBS, Cold Fusion, SQL, DTS, T-SQL, PL-SQL, IBM-MQ, Crystal Reports, Crystal Enterprise
 
I went to Query Analyzer and changed "Maximum Characters Per Column" to 8192, when I run SELECT statement from "Query Analyzer", it shows correct text(more than 255 characters), but still doesn't display correctly on the browser.
I don't think it's caused by Query Analyzer setting.
Code:
$query="select message from tb1 where id=1";
$result=mssql_query($query);
for ($i=0;$i < mssql_num_rows($result); ++$i)
{
$line=mssql_fetch_row($result);
$message=$line[0];
print "$message";
}

I doubt if "mssql_fetch_row()" cuts the text?
 
sounds like an odbc datatype problem.

if the data is fine in the database and you are positive the variables are the correct length, and the resultset is not showing the correct data, it must be the field types that driver is setting.

in php is there the equivalent parameters as there is in adodb. if so, you can create a stored procedure which receives and id and returns an output parameter containing the message in correct datatype. This should mean any problems with the driver assigning the incorrect datatype is no longer a problem?

"I'm living so far beyond my income that we may almost be said to be living apart
 
Finally I found the solution.
If I use "select message from tb1", then mssql_query() only take first 255 characters, so I have change "varchar 5000" to "text" type, or do this:

SELECT CONVERT(TEXT message) AS message FROM tb1

then it works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top