SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how is limit row to databse for display to user?

    how is limit row to databse for display to user? (like limit filde textarea for display)

    like:
    1)
    Code:
    WebMatrix makes it easy to create, customize and publish to the internet—and it’s free. Start from open source web applications, built-in web templates or just write the code yourself.
    to:
    2)
    Code:
    WebMatrix makes ...
    After clicking (2) to display the full text(1)

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, first you need to display a list of links to the user. Each of these links need to pass the id of the record they would like to see and the shortened down version of the text.

    list.php
    PHP Code:
    <?php
    $res 
    mysql_query("SELECT id, CONCAT(SUBSTR(content, 5), ' ...') AS content FROM table;");
    while(
    $record mysql_fetch_assoc($res)){
      
    printf(
        
    '<a href="view.php?id=%d">%s</a>',
        
    $record['id'],
        
    $record['content']
      );
    }
    Will display a list similar to:

    Code:
    <a href="view.php?id=1">Foo ...</a>
    <a href="view.php?id=2">Bar ...</a>
    <a href="view.php?id=3">Ying ...</a>
    <a href="view.php?id=4">Yang ...</a>
    These links point to view.php, which would use the id sent to fetch and display the record chosen.

    view.php
    PHP Code:
    <?php
    $res 
    mysql_query(sprintf(
      
    'SELECT id, content FROM table WHERE id = %d LIMIT 1;',
      
    $_GET['id']
    ));
    while(
    $record mysql_fetch_assoc($res)){
      echo 
    $record['content'];
    }
    That's a pretty general overview of the process.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If I understand you correctly, you'd use LEFT(column, x) to return x characters from a column, eg:

    Code MySQL:
    SELECT LEFT(column_name, 30) FROM table
    Martin.


Bookmarks

Posting Permissions

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