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?
MYSQL Question
Started by N0valyfe, Mar 16 2007 03:28 PM
6 replies to this topic
#1
Posted 16 March 2007 - 03:28 PM
#2
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 );
substr ( $var, 0, 150 );
#3
Posted 19 March 2007 - 06:21 AM
Or you could have MySQL do it for you.
SELECT SUBSTRING(field, 1, 150) FROM table;
#4
Posted 19 March 2007 - 08:09 AM
bay, on Mar 16 2007, 07:22 PM, said:
yep, just query the result as you normally would, and when you are using it, just use substr ();
substr ( $var, 0, 150 );
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_*
Posted 19 March 2007 - 02:55 PM
It goes with the query for the data you are wanting to limit.
#6
Posted 19 March 2007 - 03:46 PM
Herbert, on Mar 19 2007, 08:09 AM, said:
bay, on Mar 16 2007, 07:22 PM, said:
yep, just query the result as you normally would, and when you are using it, just use substr ();
substr ( $var, 0, 150 );
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
Posted 22 March 2007 - 01:32 PM
SecondV, on Mar 19 2007, 05:21 AM, said:
Or you could have MySQL do it for you.
SELECT SUBSTRING(field, 1, 150) FROM table;
Herbert, on Mar 19 2007, 07:09 AM, said:
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 );
??????????
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/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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
