Jump to content

select newest


doddsey_65

Recommended Posts

Something along these lines...

 

  // Query database for latest 5 records
  $myQuery = mysql_query("SELECT * FROM `YOURDATABASEHERE` ORDER BY `timestamp` DESC LIMIT 5");
  // While the query runs we will echo each row
  while($myQuery = mysql_fetch_assoc($myQuery)) {
    print_r($myQuery);  // Print out each row as an array
  }

 

That should display the latest 5 rows, just append the "print_r($myQuery);" to format the data recieved ect...

 

Regards, Paul.

Link to comment
Share on other sites

Leading line syndrome right? I used to get that...

 

Try this...

  if(strstrlen($row[fieldname]) > 50) {
    $leadingLine = trim(substr($row[fieldname],0,50));
    $leadingLine = ''.$leadingLine.'...';
  } else {
    $leadingLine = $row[fieldname]
  }

 

Off the top of my head buddy, not 100% sure it is correct but give it a go :)

 

Regards, Paul.

Link to comment
Share on other sites

One limitation of the above code snippet is that it doesn't break the line on a full word. This is the typical behavior when getting an excerpt of a line. Otherwise you could end up with something very unintended if a word gets broken in the wrong place.

 

Here is a function I keep in my personal library:

function truncateString($string, $length, $ellipse='...')
{
    if (strlen($string) <= $length) { return $string; }
    return array_shift(explode("\n", wordwrap($string, $length))) . $ellipse;
}

 

Just pass the string, the maximum length, and the value to use for the ellipse (optional, default is '...')

Link to comment
Share on other sites

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.