Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts

    EZ Problem, im stumped though

    hello and good morning
    Ok, each game listed in my arcade displays a description, which i put in red on the code below, I want it so that only the first 20 charectors of the description is displayed then theres a "..." after it, i know this is probably an easy problem and i looked most everywhere but i couldnt find a solution.
    <TR>
    <TD>
    <tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="categHead">
    <tr><td>&nbsp; Action / Adventure </td> </tr></table></td></tr><tr><td>

    <TABLE cellSpacing=6 cellPadding=0 width="100%"
    border=0>
    <div align="center">
    <table width="500" border="0">
    <tr>
    <td><div align="center">
    <table width="500" border="0">
    <tr>
    <td width="494" height="0" valign="top">
    <center>
    <p><font size="1">
    <?
    $sql2 = "SELECT * FROM games WHERE category='Action / Adventure' ORDER BY played DESC LIMIT 0,3";
    $result2 = mysql_query($sql2);
    while($row2 = mysql_fetch_array($result2)) {
    ?>
    <table width="400" border="0">
    <tr><td>
    <td width="50%" valign="top"><table width="494" border="0" cellpadding="0" cellspacing="3" class="game">
    <td width="100"><img src="images/<? echo $row2["image"]; ?>" height="60" width="60"></td>
    <td valign="top" width="234" class="normalText">
    <div style='text-align:right; overflow:hidden; height:14px;'><a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><FONT color=#000000><? echo $row2["category"]; ?> Games!</a></font></div>
    <a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><b><? echo $row2["name"]; ?></b></a><br>
    <? echo $row2["desc"]; ?><br>
    <a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><b>Play now!</b></a></font></td></table>

    </a>
    <tr></td>
    any help is greatly appriciated, thanks in advance

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a thread where someone asked the same question:
    http://www.codingforums.com/showthread.php?p=407749

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Along with the solutions in the previously linked threads, you can also pull this directly from the database and bypass any extra php work:

    Code:
    SELECT
     CONCAT(LEFT(desc,20),'...') AS desc
    ,etc.
    If you'd rather have your breaks on words:

    Code:
    SELECT
     CONCAT(SUBSTRING_INDEX(desc,' ',10),'...')
    ,etc.
    That'll return everything to the left of the 10th space.

  • #5
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem with that is that 3 dots will always be appended (although you could do a case or an if probably to have it flop to what you want based on string length).

  • #6
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the replies

    I looked at both the links, and I didn't understand them

    I'm sorry but I am fairly new to php, could someone tell me what to replace the line below with to make it show just the first 20 charectors

    <? echo $row2["desc"]; ?>
    thanks in advance

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks
    Last edited by Al Capone; 02-17-2006 at 02:04 AM.

  • #8
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Al Capone
    hey sup, usually i dont double post but i am on a deadline and need to finish my site up, can someone please help me, thanks
    but 3 solutions have already been posted to the thread, oh wait, you want us to do the work for you? you have a deadline? what have you been hired for? when do you think you will try understanding the code? this is absurd.

    anyway

    PHP Code:
    <?php 

    $min_length 
    30;
    if (
    strlen($row2['desc'])>$min_length)
        echo 
    substr($row2['desc'], 0strrpos(substr($row2['desc'], 0$min_len), ' ')).'...';
    else
        echo 
    $row2["desc"];

    ?>

  • #9
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks bro, il try it

    I have homework, thats the deadline i was just waiting by my computer, browser open, doing homework

    thanks again bro

  • #10
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Al Capone
    Thanks bro, il try it

    I have homework, thats the deadline i was just waiting by my computer, browser open, doing homework

    thanks again bro

  • #11
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it didnt work, i only see ... thats it

    any idea whats wrong?

  • #12
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had a typo in my post, you are obligated to figure out what it is.

  • #13
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awww man, ok,

    one of them was that the min should be max right? well i tried that didnt work

    and the other was that you wrote 30 not 20 i made it 20, that didnt work either

    so this is what i have now


    <?php

    $max_length = 20;
    if (strlen($row2['desc'])>$max_length)
    echo substr($row2['desc'], 0, strrpos(substr($row2['desc'], 0, $max_len), ' ')).'...';
    else
    echo $row2["desc"];

    ?>

  • #14
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    keep trying

  • #15
    Regular Coder
    Join Date
    Feb 2006
    Posts
    149
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind, you just spelled the length wrong,

    Thank you so much

    Now I will go finish my homework

    thanks again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •