Reply
Database Question...
Old 08-01-2005, 12:40 PM Database Question...
Brian07002's Avatar
Webmaster Talker

Posts: 526
Name: Brian
Location: United States
Hi All,

I am trying to do this simple database task but having a problem...

I want to shorten the names of my products (item names) to 34 characters so I went to the MysQL database and shortened the field type from Varchar(100) to Varchar(34) and it did shorten, however, because some of my item names are quite long, they just wrap to the next line (there in a table cell).

My question is how can I 'cut' or delete the remaining part of the item name so they are only 34 characters instead of wrapping the remaining part of the item name to the next line? Or even add the famous '...' after the maximum characters are displayed and there are more remaining.

Thank you in advance!

-Brian
__________________
Brian
TMS BBS: 201-471-2205
Open Friday thru Sunday Eastern Time (US & Canada)

Last edited by Brian07002 : 08-01-2005 at 12:43 PM.
Brian07002 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-01-2005, 02:01 PM
Unknown.

Posts: 1,693
This will do as you wish..
PHP Code:
$string_length strlen($VAR_NAME);

if (
$string_length 34) {
$VAR_NAME substr($VAR_NAME,0,34) . "...";

You just need to change all the $VAR_NAME's to the name of the variable that holds the value.
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-01-2005, 03:40 PM
Brian07002's Avatar
Webmaster Talker

Posts: 526
Name: Brian
Location: United States
Hi,

Could you give that to me so I can add it to phpMyAdmin, instead of making a php file out of it?

The reason I ask this way is because I have multiple table that have the same field name. The field that I want this to change is called 'name' in the category table. But I also have 'name' in the users table too. I only want to change the name field in the category table, no where else.

Thank you!
-Brian
__________________
Brian
TMS BBS: 201-471-2205
Open Friday thru Sunday Eastern Time (US & Canada)

Last edited by Brian07002 : 08-01-2005 at 03:48 PM.
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 08-01-2005, 05:46 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Doing it in php shouldn't affect any of the other fields in any of your other queries.
PHP Code:
$result1 mysql_query("select name from table1");
$result2 mysql_query("select name from table2");

$name1 mysql_result($result1,0,'name');
$name2 mysql_result($result2,0,'name');

echo 
$name1;
echo 
substring($name2,0,34) . '...'
That code will leave name1 unaffected and will shorten name2.

You can achieve the same affect in SQL directly if you want to:

Code:
SELECT CONCAT(SUBSTRING(name,1,34),'...') AS short FROM tablename;
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to Database Question...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12629 seconds with 12 queries