Jump to content

[SOLVED] Limit on displayed results


stelthius

Recommended Posts

Hello guys, just wondering if i limit a result brought back from the DB to 65 characters is there anyway to split the limited results returned into seperate lines like...

 

 

This is a result returned back from

the databse is there a way to make

it show like this...

 

Rather than like this.

 

This is a result returned back from the databse is there a way to make it show like this...

 

i know my explanation is probably horrid but its the best way i acn think of wording what i need to ask. If anyone has any ideas id be greatfull.

 

 

 

Link to comment
Share on other sites

You're probably looking for wordwrap() or if you want to be exactly 65 chars, chunk_split()

 

Try running this and seeing which you like better (see attached image for what the results are):

<?php
$longVar = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et consectetur tortor. Donec nec ante arcu. Proin consectetur, turpis non vehicula dignissim, lectus ante pretium nunc, vitae ultricies enim lacus quis purus. Nulla imperdiet ornare tempor. Proin sit amet aliquet tellus. Sed quis ligula vitae urna pharetra dictum. Suspendisse potenti. Integer a rhoncus odio. Donec porta, massa nec feugiat auctor, purus urna tempus leo, ac mattis metus tortor eu metus. Integer tincidunt mattis scelerisque. Nulla mi tellus, dignissim sed fermentum ac, lacinia vitae mi. Phasellus tortor diam, accumsan vitae pulvinar id, malesuada eu velit. Duis pharetra urna et massa ultrices mattis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer blandit pharetra purus, vel interdum arcu rutrum sed. Donec id tincidunt dolor. In hac habitasse platea dictumst.';
echo $longVar,'<hr>';
echo chunk_split($longVar, 64, '<br>');
echo '<hr>';
echo wordwrap($longVar, 64, '<br>');
?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

Hello Phillip, it is the third one i need but my code is like this...

 

$query = "SELECT * FROM users ORDER BY signupdate DESC LIMIT 5";
$results = mysql_query($query) or die(mysql_error());
while ($value = mysql_fetch_array($results)) {
$value["about_me"] = substr($value['about_me'], 0, 65);

 

As you can see it calls the about_me and limits it to display 65 chars, now my problem is getting it to show say 500 chars, but showing them in the way your code has done in part 3 of you're image, to be quite honest im glad you understood what i meantr as it was a pain trying to explain it, Anyways after looking at your code how would i get them to intergrate as one is a query the other is a code instruction the text to perform in a certain way.. if im wrong please correct me..

Link to comment
Share on other sites

Well after looking over your snippet, i took into consideration what you had said and showed me and fianlly got this..

 

while ($value = mysql_fetch_array($results)) {
$value["about_me"] = wordwrap($value['about_me'], 64, '<br>');

 

Which is now working perfectly and as i wanted it too.

 

Thanks Phillip!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.