Click to See Complete Forum and Search --> : Display MySQL results only partially
thedigitalnomad
08-24-2005, 12:53 AM
I've actually been having some good luck with my project today, but I've got a question I haven't really seen elsewhere (though, I didn't really look terribly hard).
Say, I've got a while loop displaying some rows of data from MySQL, and for one of the elements ($row['entry']), I only want it to display, say, the first 30 characters or so, instead of the whole thing.
I know I've seen it before, but I'm lost as to how I'd do it. Any help?
Sheldon
08-24-2005, 12:55 AM
max php functions (http://nz.php.net/manual/en/function.max.php)
thedigitalnomad
08-24-2005, 01:09 AM
...
I'm not sure if that's what I'm looking for. max() returns the largest value out of whatever you put inside the perentheses, from what I understand. I could just not be understanding how I'm supposed to use this?
I'm not sure how to clarify what I would like to do o.O
When I echo $row['entry'], I only want the first 30 characters in the LARGETEXT field to be displayed. Then, I've got a link to a separate page that displays the whole thing. While I've got the latter down, I don't know how to go about just displaying the first 30 characters...
You want to use substr() (http://nz.php.net/manual/en/function.substr.php).
$short_version = substr($long_version,0,30); // First 30 characters
Additionally, if you want to put the dot dot dot at the end, you could do:
$short_version = strlen($long_version) > 33 ? substr($long_version,0,30).'...' : $long_version; // Display dots if the string is longer than 33 characters
thedigitalnomad
08-24-2005, 01:53 AM
Thank you, Mau. Exactly what I needed :D