Jump to content

limit words


kvnirvana

Recommended Posts

Can't seem to get this code to work. What I want to do is to get the first 5 letters from comment. I get this message Undefined index: comment

I know it has something to do with this part LEFT('comment', 5) because if I remove it it shows the result.

 

<?php


echo '<p ><strong>Seneste kommentarer</strong></p>'; 
mysql_connect("", "", "") or
    die("Could not connect: " . mysql_error());
mysql_select_db("");

$result =  mysql_query ("SELECT * LEFT('comment', 5) from comments where user_id='51'" ) or die(mysql_error());




echo "<table border='1'>";
echo "<tr> <th>Comments</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['comment'];
echo "</td><td>"; 

} 

echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/218577-limit-words/
Share on other sites

Ok I've got this

 

$result =  mysql_query ("SELECT * LEFT('comment', 5) AS truncated from comments where user_id='51'" ) or die(mysql_error());




echo "<table border='1'>";
echo "<tr> <th>Comments</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['truncated'];
echo "</td><td>"; 

} 

echo "</table>";

 

But I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT('comment', 5) AS truncated from comments where user_id='51'' at line 1

Link to comment
https://forums.phpfreaks.com/topic/218577-limit-words/#findComment-1133808
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.