stelthius Posted May 22, 2009 Share Posted May 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/ Share on other sites More sharing options...
elgoog Posted May 22, 2009 Share Posted May 22, 2009 Do you need to put a character limit on it, or just limit to a certain width? Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-839986 Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 You're probably looking for wordwrap() or if you want to be exactly 65 chars, chunk_split() Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-839993 Share on other sites More sharing options...
stelthius Posted May 22, 2009 Author Share Posted May 22, 2009 to be quite honest im limiting it to 65 right now due to the fact i dont want the results right accross the screen but if i can figure out how to limit & split the results to a new line that would be incredibly awsome. Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-839998 Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-840016 Share on other sites More sharing options...
stelthius Posted May 22, 2009 Author Share Posted May 22, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-840037 Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 Its just how you think it would be //... while ($value = mysql_fetch_array($results)) { $aboutMe = wordwrap($value['about_me'], 64, '<br>'); //... Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-840040 Share on other sites More sharing options...
stelthius Posted May 22, 2009 Author Share Posted May 22, 2009 Oh! i really didnt think it would be that simple! well thanks phillip greatly appretiated.. Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-840045 Share on other sites More sharing options...
stelthius Posted May 22, 2009 Author Share Posted May 22, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/159263-solved-limit-on-displayed-results/#findComment-840054 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.