Jump to content


Photo

MYSQL Question


  • Please log in to reply
6 replies to this topic

#1 N0valyfe

N0valyfe

    Young Padawan

  • Members
  • Pip
  • 15 posts

Posted 16 March 2007 - 03:28 PM

I'm using mysql with php and im wondering if its possible to limit the amount of letters it displays, say i take something from a field with the type as 'text' and i want it to only display the first 150 letters from that field is it possible?

#2 bay

bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 16 March 2007 - 06:22 PM

yep, just query the result as you normally would, and when you are using it, just use substr ();

substr ( $var, 0, 150 );

#3 SecondV

SecondV

    Young Padawan

  • Members
  • Pip
  • 28 posts
  • Gender:Male
  • Location:Kentucky
  • Interests:All things PHP & MySQL :)

Posted 19 March 2007 - 06:21 AM

Or you could have MySQL do it for you.

SELECT SUBSTRING(field, 1, 150) FROM table;


#4 Herbert

Herbert

    Young Padawan

  • Members
  • Pip
  • 35 posts
  • Location:Under Your Bed!
  • Interests:Computers, Rock Music, Cars, Girls!

Posted 19 March 2007 - 08:09 AM

yep, just query the result as you normally would, and when you are using it, just use substr ();

substr ( $var, 0, 150 );



I needed this too. Thanks. But one question, where does it go??

Hold on lol. OK here is an example:
If i wanted to display names from my db and i used:

$names

Then to limit the name size, i would use:

substr ( $name, 0, 150 );

??????????

#5 _*Creative Insanity_*

_*Creative Insanity_*
  • Guests

Posted 19 March 2007 - 02:55 PM

It goes with the query for the data you are wanting to limit.

#6 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 19 March 2007 - 03:46 PM

yep, just query the result as you normally would, and when you are using it, just use substr ();

substr ( $var, 0, 150 );



I needed this too. Thanks. But one question, where does it go??

Hold on lol. OK here is an example:
If i wanted to display names from my db and i used:

$names

Then to limit the name size, i would use:

substr ( $name, 0, 150 );

??????????



If you were to use it like that, it would look like this.

echo substr($name, 0, 150);

If you are using an array, you would have to iterate the array with either a loop, or a function like array_map().

#7 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 22 March 2007 - 01:32 PM

Or you could have MySQL do it for you.

SELECT SUBSTRING(field, 1, 150) FROM table;

You could, but having php do it is by far faster than having sql do it. In fact, having mysql use any "functions" slows things down quite a bit.

I needed this too. Thanks. But one question, where does it go??

Hold on lol. OK here is an example:
If i wanted to display names from my db and i used:

$names

Then to limit the name size, i would use:

substr ( $name, 0, 150 );

??????????

http://php.net/substr
http://php.net/manua...fetch-array.php

Please try doing a little research. You'll be surprised how many questions have been answered before you even think to ask them.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users