Jump to content

Recommended Posts

I have this code that will retreive the names of Flash Movies/Games from my website...

 

<?php
include("include/connect.php");
$sql = "SELECT * FROM flashid ORDER BY flashid DESC LIMIT 20";
$res = mysql_query($sql) or die (mysql_error());
while($r=mysql_fetch_assoc($res)){
echo "<a href=\"viewflash.php?flashid=".$r['flashid']."\">".$r['flashname']."</a></br>";
}

?>

 

Now, how would I make it so that if the name is longer than 20 letters, it will replace the last 3 letters with "..."? Because names longer than 20 letters will stretch my tables, so I suppose "..." will be good enough to simply signify the name is longer.

Link to comment
https://forums.phpfreaks.com/topic/40612-solved-display-a-maximum-20-letters/
Share on other sites

in my previous post, we're manipulating a string. this string is called $string. now, for you, it would be whatever string that you wanted to manipulate... so that would be $r['flashname']. so this is how you impliment it into your code:

<?php
        include("include/connect.php");
        $sql = "SELECT * FROM flashid ORDER BY flashid DESC LIMIT 20";
        $res = mysql_query($sql) or die (mysql_error());

        while($r=mysql_fetch_assoc($res)){
                if(strlen($r['flashname']) >= 20){
                        $r['flashname'] = substr($r['flashname'], 0, 17) ."...";
                }
                echo "<a href=\"viewflash.php?flashid=".$r['flashid']."\">".$r['flashname']."</a></br>";
        }
?>

 

 

 

P.S. don't forget to click the 'topic solved' mod at the bottom-left of this thread.

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.