jason97673 Posted May 9, 2007 Share Posted May 9, 2007 Hello, I am trying to retrieve data in my PHP page. I can do that successfully, however I would like to retrieve perhaps the first 75 characters of the result set. For example I am making a website that on the front page has the latest news etc. Well right below the latest news I have a <DIV> and it is relatively positioned so I need to make sure the short descriptions of these news excerpts don't end up overlapping my DIV. Should be rather simple as I am sure there is a simple keyword for it somewhere. Any help appreciated. Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/ Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 Check out the substr() function. Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249301 Share on other sites More sharing options...
jason97673 Posted May 9, 2007 Author Share Posted May 9, 2007 Sounds like a PHP Function? Would I then solve the problem in my PHP or in the SQL? Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249304 Share on other sites More sharing options...
cmgmyr Posted May 9, 2007 Share Posted May 9, 2007 that is a php function Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249312 Share on other sites More sharing options...
jason97673 Posted May 9, 2007 Author Share Posted May 9, 2007 Thanks for the replies. I checked out http://us2.php.net/substr But being that I have $data = mysql_query("SELECT * FROM info where front_page='1'") or die(mysql_error());//Display Error message echo '<table id="news_table">'; echo '<tr>'; echo '<td><b>Latest News and Announcements</b></td>'; echo '</tr>'; while ($info=mysql_fetch_array( $data )) { echo '<tr>'; echo '<td><a href="showarticle.php?article_id=' .$info['article_id'] .'">' .$info['title'] .'</a></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="text2">Date Published: <b>' .$info['created'] .'</b></td>'; echo '<tr>'; echo '<td colspan="2">' .$info['short'] .'</td>'; echo '</tr>'; echo '<tr>'; echo '<td><hr /></td>'; echo '</tr>'; } echo '</table>'; I'm not very sure how substr() would fit into that very well. Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249313 Share on other sites More sharing options...
effigy Posted May 9, 2007 Share Posted May 9, 2007 MySQL's SUBSTR. Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249317 Share on other sites More sharing options...
bubblegum.anarchy Posted May 10, 2007 Share Posted May 10, 2007 As effigy stated. SELECT substr(value, 0, 75) AS value_trim FROM table Link to comment https://forums.phpfreaks.com/topic/50711-display-x-characters/#findComment-249450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.