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
https://forums.phpfreaks.com/topic/213190-select-newest/#findComment-1110114
Share on other sites

thanks, another thing is i want to display the contents of another table but if the content has more than say 50 characters then i want to replace all remaining characters with three dots to signify a continuation. how would that be done?

Link to comment
https://forums.phpfreaks.com/topic/213190-select-newest/#findComment-1110117
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
https://forums.phpfreaks.com/topic/213190-select-newest/#findComment-1110120
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
https://forums.phpfreaks.com/topic/213190-select-newest/#findComment-1110122
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.