Hi, Using Dreamweaver, PHP and mySQL.. calling data from the database and displaying it on page, but would like to only display 2 lines or say 200 characters (which ever is easiest) followed by ... Here is my code, can anyone shed light on how to do this.. Cheers <td> <h3> <a href="tour-details.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."ID=".urlencode($row_rsNSWSS['ID']) ?>" class="linkblue"><?php echo $row_rsNSWSS['Synopsis']; ?></a> </h3> </td> PS: I am not a programmer, hence teh use of Dreamweaver to do all the hard work
So you need to trim it? <?php function short_name($str, $limit) { // Make sure a small or negative limit doesn't cause a negative length for substr(). if ($limit < 3) { $limit = 3; } // Now truncate the string if it is over the limit. if (strlen($str) > $limit) { return substr($str, 0, $limit - 3) . '...'; } else { return $str; } } ?>
SELECT `ID`, SUBSTRING(Synopsis, 1, 200) FROM `table` Code (sql): Change your query to something similar to this.
Tried the substring option, but I couldn't get it working.. The text did not display at all.. Here is the SELECT statement I have and the DISPLAY statement I use.. mysql_select_db($database_RDVF, $RDVF); $query_rsNSWSE = "SELECT ID, City, GroupDivider, TourTitle, Synopsis FROM tourdetails WHERE GroupDivider = 'NSWSE' ORDER BY TourTitle ASC"; $rsNSWSE = mysql_query($query_rsNSWSE, $RDVF) or die(mysql_error()); $row_rsNSWSE = mysql_fetch_assoc($rsNSWSE); $totalRows_rsNSWSE = mysql_num_rows($rsNSWSE); <a href="tour-details.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."ID=".urlencode($row_rsNSWSE['ID']) ?>" class="linkblue"><?php echo $row_rsNSWSE['Synopsis']; ?> </a> Any input greatly appreciated.. regards, Ken
<td> <h3> <a href="tour-details.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."ID=".urlencode($row_rsNSWSS['ID']) ?>" class="linkblue"><?php echo substring($row_rsNSWSS['Synopsis'],0,300); ?>...</a> </h3> </td> PHP: Peace,
function split_text($text, $number_of_words){ return implode(' ',array_slice(explode(' ',$text),0,$number_of_words)); } PHP: This function return the first X words of a string assuming that the word separator is ' ' (space), this function is very basic of course and may cause problems if your string contains html echo split_text("Hey! What's up?", 1) // Output: Hey! echo split_text('<a href="#">This is a link</a>', 5) // Output: <a href="#">This is a link // (you have a missing </a> tag) PHP:
Hi, I tried Azizny's solution, and the page failed to display anything from theat uploaded line of code onwards.. Here is teh link to the page without restricting the FIELD http://www.rdvaustralie.com/nsw-tours.php Here is a link to a page that have one line of AZIZNY's code inserted http://www.rdvaustralie.com/nsw-tours-1.php Happy New Year to all.. Regards, Ken