RyanSF07 Posted January 15, 2010 Share Posted January 15, 2010 Hello, I've got: $query_result2 = mysql_query($sql2); while ($row2 = mysql_fetch_array($query_result2)) { listing content in a table with: <td style=\"padding: 3px 20px 5px 3px\"><p>".$row2['assignment']."</p></td> I would like to limit the number of characters of the 'assignment' to 50. I tried: row2['assignment_number'] = $assign; if(strlen($assign)>50){ echo substr($assign, 0, 50); } and then listing it with: <td style=\"padding: 3px 20px 5px 3px\"><p>".$assign."</p></td> but that didn't work. Any pointers on how to accomplish this? Thank you, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/188615-help-limiting-number-of-characters-pulled-from-database/ Share on other sites More sharing options...
taquitosensei Posted January 15, 2010 Share Posted January 15, 2010 you were pretty damn close row2['assignment_number'] = $assign; if(strlen($assign)>50){ $assign= substr($assign, 0, 50); } Quote Link to comment https://forums.phpfreaks.com/topic/188615-help-limiting-number-of-characters-pulled-from-database/#findComment-995760 Share on other sites More sharing options...
rpmorrow Posted January 15, 2010 Share Posted January 15, 2010 You are trying to test and trim your empty variable. Use this instead.. $assign = row2['assignment_number']; if(strlen($assign)>50){ echo substr($assign, 0, 50); } Quote Link to comment https://forums.phpfreaks.com/topic/188615-help-limiting-number-of-characters-pulled-from-database/#findComment-995762 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.