1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Limited amount of text from record

Discussion in 'PHP' started by save, Aug 21, 2007.

  1. #1
    How would I be able to only show say 300 characters from the description field when I retrieve records from MySQL?

    $query = "SELECT id, name, price, image_url, description FROM `products` ORDER BY rand() LIMIT 4;";
    database_inquiry($query, $rows);
    $products = $rows;
    
    
    <?=$item['description']; ?>
    Code (markup):
     
    save, Aug 21, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well...do you want mysql to limit what it returns for the description to <= 300 characters, or do you want mysql to return the entire description and do the limiting in php?
     
    sea otter, Aug 21, 2007 IP
  3. save

    save Active Member

    Messages:
    1,047
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    80
    #3
    i want to do the limiting in php
     
    save, Aug 21, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?=substr($item['description'],0,300); ?>
    
    PHP:
     
    sea otter, Aug 21, 2007 IP
    save likes this.
  5. save

    save Active Member

    Messages:
    1,047
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    80
    #5
    rep added, cheers!
     
    save, Aug 21, 2007 IP
  6. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Thank you very much

     
    baris22, Nov 29, 2007 IP