Jump to content

Display picture with max date


runnerpaul

Recommended Posts

Hi,

 

I have the following table:

 

ID picName          description                                                         date

1 Us Time.jpg A couple watching the sunset at Ballintoy Harbour 2011-02-04

2 Pic.jpg         This is the house on Castle Island taken in fog. 2011-02-03

3 catblack.jpg Pic of a cat                                                         2011-02-05

 

I am trying to display th picName that belongs to the highest date but only know how to display all pictures. Can anybody help me?

 

Here is what I have:

 

<?php
  		include("db.inc");                                 

  		$cxn = mysqli_connect($host,$user,$password,$dbname) 
        or die ("couldn't connect to server");

	/* Select  */
  		$query = "SELECT * FROM pictures";
  		$result = mysqli_query($cxn,$query)
            or die ("Couldn't execute query."); 

	while($row = mysqli_fetch_assoc($result)) 
        {
   		echo "<tr><td colspan=2> </td>
			 <td><img src='./images/{$row['picName']}' border='0' width='500' height='400' /><p></td></tr>\n";	
	}
?>

Link to comment
https://forums.phpfreaks.com/topic/226769-display-picture-with-max-date/
Share on other sites

Ah thats great. Cheers.

 

If I then wanted to add a link that pulls a picture where date is equivalent to the current date selected - 1 day. i.e. the picture from the previous day.

 

Apolgies if this is simple or obvious. I havnt looked at php in 6 years and havnt a clue about it.

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.