Link to home
Start Free TrialLog in
Avatar of jillybabe
jillybabe

asked on

Restricting length of output

Hi

I am still trying to learn this stuff and I am stumped!

HELPPPP!!!

I am trying to build a search thing where I print results to a webpage but the result from the Mysql database is too long and ruining the look of my page...

Can someone tell me how I restrict the length of the result from $row[Description} to X characters?

Thanks

Jilly
Avatar of a.marsh
a.marsh

You mean restrict the number of records it pulls out or the length of, say, a text field?

If the first then use LIMIT e.g.

select title from table_name order by title limit 10;

That will list the first 10 records it finds (after sorting the data).

Or you can use:

select title from table_name order by title limit 5, 10;

This will list 10 records starting from the 5th record.

:o)

Ant
If you want to restrict the number of characters you print for a field, you can use substr, to get just a piece of a string.

Also, I usually make a table when displaying results. You can set the width of each cell, and your browser will adjust. You may get several lines per row, though.

Orlando
Yes, if that is what you mean you can use substr - but that is within PHP - I always prefer to get the database to setup the data as best as possible and there is an equivalent function in MySQL called substring.

If you can clairfy exactly what it is you want we can give you the complete solution.

:o)

Ant
Avatar of jillybabe

ASKER

I have given the field too much space char(150) when it only needs 50!

Is it possible to simply change the size of this using ALTER?

Will it simply remove all the extra characters if I do?

Jilly
ASKER CERTIFIED SOLUTION
Avatar of a.marsh
a.marsh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a Lot!

That is exactly what I shall do :-)

Jilly
Check out:

http://www.mysql.com/doc/A/L/ALTER_TABLE.html

for all there is to know about it.

Ant