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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.