Jump to content


Photo

solved---only print some of an entry


  • Please log in to reply
7 replies to this topic

#1 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 18 August 2006 - 04:05 AM

Is there any way to print lets say the first 100 characters of a text entry?
To go along with this is there anyway to check the length of a text entry?
Any help would be GGGGRRRRRREAT!



#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 18 August 2006 - 04:07 PM

1. LEFT( yourColumn, 100 )
2. LENGTH( yourColumn)
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 20 August 2006 - 05:10 PM

these dont seem to work for me... and i cant find them in the either the php or mysql manuals
if im supposed to write them how do i take out one character of a string?

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 August 2006 - 05:39 PM

To elaborate on Fenway's answer about printing 'some' of a field, his method is designed to abstract a defined length of data from a MySQL data field.  Example:

$query = "SELECT left(your_column_name, 100) FROM your_table_name .... "; // retrieve ONLY 100 characters

Alternatively, you can abstract ALL of the database data and use the substr() function to print a portion of it.  The php manual provides lots of examples of substr() use.
Legend has it that reading the manual never killed anyone.
My site

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 August 2006 - 05:48 PM

MySQL has an equivalent set of string functions as well, depending on what exactly it is that you're doing in the end.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 20 August 2006 - 06:15 PM

heres what i have
$query = "SELECT news.newsID, news.pictureID, news.name AS newsName, news.abstract, left('news.fulltext',100), date.name " .
  "FROM news, date WHERE news.dateID = date.dateID ORDER BY date.name";

i tried this too
$query = "SELECT news.newsID, news.pictureID, news.name AS newsName, news.abstract, left(news.fulltext,100), date.name " .
  "FROM news, date WHERE news.dateID = date.dateID ORDER BY date.name";

and i looked at these commands and found nothing
http://www.mysqlfrea..._statements.php
is there another manual?
THANKS!
PS the substr() works i just tried it but i figure this will process faster

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 05:30 PM

What makes you think it doesn't work? Granted, you don't have a column alias, so it'll be hard to "find" in your hash.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#8 chico1st

chico1st
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 22 August 2006 - 04:26 AM

well i couldnt get a result from it so i figured the syntax was wrong.. but if i need an alias thats that :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users