Re: PHP Snippet on a web page - SOLVED
| From: | Bluejays PC Services | Date: | Sun, 12 Mar 2006 12:17:08 +0000 |
| Subject: | Re: PHP Snippet on a web page - SOLVED | ||
| References: | 1 2 3 4 | Groups: | php.install |
| Request: | Send a blank email to php-install+get-17168@lists.php.net to get a copy of this message | ||
Pam
Hi, that didn't work 1st time although it certainly got me moving in the right direction.....it repeated each word (1 to 10) with the hypertext link "read more>>>" attached to each word which was very messy indeed.
I did a bit of juggling around and managed to get it perfect.
Many thanks for your help, greatly appreciated.
Regards
Jeremy
FYI:
<?php
function cut_string($string,$wordnum)
{
$string_arr=explode(" ",$string);
for($i=0;$i<$wordnum;$i++)
{
$re_string=" ".$string_arr[$i];
$str=$re_string;
print $str;
}
}
//connect, select db, create query, run query, close connection
$conn=mysql_connect("localhost", "userid", "password") or die(mysql_error());
$database=mysql_select_db("fback", $conn)or die(mysql_error());
$sql="SELECT * FROM customer_feedback ORDER by id DESC LIMIT 25"; $result=mysql_query($sql);//PHP goes into while loop to return summaries of comments while($row=mysql_fetch_array($result)){ echo"<TR><td><B>Date: " .strftime('%d/%m/%y',strtotime($row["date"]))."</B></td> <td><B>Comment By:</B> ".Stripslashes($row["name"])."<td></tr>"; echo"<TR><TD COLSPAN=\"2\" valign\"top\"><B>Comment: </B>"; stripslashes(nl2br(cut_string($row["comment"],"10"))); echo"<a href=\"full_summ.php?id=$row[id]\">More>>> </a>"; echo"<hr></td></tr>"; } //close database mysql_close($conn); ?>
Oops - spotted it - try this function cut_string($string,$wordnum,$trail) {-- Jeremy Oliver Bluejays PC Repair tel 020 8656 1056 mob 07855833401 www.bluejayspc.co.uk$string_arr=explode(" ",$string); for($i=0;$i<$wordnum;$i++){ $re_string=" ".$string_arr[$i]; $str=$re_string.$trail; print $str; } }Pam