I am using the following Code, to get data from the Database in phpmyadmin, and showing it in a html table. In the message column i have put a view link, to show the complete message when clicked. I have truncated the message successfully. Now that the View Link’s onclick event is not working. Please see if i am doing sth wrong.:
<?php $i=0;?>
<table border="1" style="position:absolute; left: 197px; top: 50px;">
<tr>
<td width="236" style="font-family:Ravie; color:#313253; text-align:center">Name</td>
<td width="225" style="font-family:Ravie; color:#313253; text-align:center">
Email Address</td>
<td width="267" style="font-family:Ravie; color:#313253;
text-align:center">Message</td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"FullName");
$f2=mysql_result($result,$i,"EmailAddr");
$string=mysql_result($result,$i,"Message");
$limit=10;
$string1 = myTruncate($string,$limit);
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $string1; ?></font>
<a href="" onclick="<?php echo $string; ?>">View</a></td>
</tr>
<?php
$i++;
}
?>
</table>
The
onclickrequires Javascript code, you can’t just enter raw content and expect it to show after a click. Do you want to use analert()messagebox to show the message? If so, try:If you’re
$stringhas any quotes in it you’ll need to escape them.I suggest adding the onclick event handler separately, for example on page load, rather than inline.