Solved

Restricting length of output

Posted on 2001-07-25
7
245 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:jillybabe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6319091
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
0
 
LVL 2

Expert Comment

by:curri
ID: 6319485
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
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6319825
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jillybabe
ID: 6321092
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
0
 
LVL 15

Accepted Solution

by:
a.marsh earned 50 total points
ID: 6321108
Yes you can change the size of it using ALTER and yes it will truncate all data to 50 chars in length.

Ant
0
 

Author Comment

by:jillybabe
ID: 6321117
Thanks a Lot!

That is exactly what I shall do :-)

Jilly
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6321134
Check out:

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

for all there is to know about it.

Ant
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question