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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2010
    Posts
    53
    Thanks
    3
    Thanked 0 Times in 0 Posts

    If length of result

    Current:
    Code:
      echo "<td width=20%>" . substr($row['CNotes'],0, 100) . " </td>";
    Desired result:
    Code:
      echo "<td width=20%>" . substr($row['CNotes'],0, 100) . IF LENGTH(CNOTES)>100 THEN "CLICK HERE TO VIEW MORE"" </td>";

  • #2
    New Coder
    Join Date
    Apr 2010
    Posts
    53
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Or if it is over 100, just "..." added to the end. Something to show there is more. I don't know how to add an if after the " . "

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,916
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    Nothing to do with MySQL. This is exclusively a PHP question.

    The answer is the same if no database is involved.

    Code:
    $cnotes =  $row["CNotes"];
    echo "<td width=20%>" . substr($cnotes,0, 100);
    if ( strlen($cnotes) > 100 ) 
    {
        echo '<a href="showMore.php?id=' . $row["ID"] . '">... CLICK HERE TO VIEW MORE</a>';
    }
    echo "</td>";
    That shows having the user open a separate page to "view more" (using a hypothetical ID field from your DB table).

    But if you instead wanted to use JavaScript to do the "show more", then you'd need to figure out the right JS code to drop in there. NOTE: Of course, if somebody has JS disabled, that's maybe not a viable answer.

    EDIT: Corrected the error iBall showed. But I don't expect the above answer to be used, anyway. Almost surely you are going to want a better answer. But it's hard to give that without knowing WHAT you want. Oh, and I should have given the caveat that I don't code in PHP. If you had asked for a MySQL answer, I think I would get that right.
    Last edited by Old Pedant; 04-24-2012 at 07:10 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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