Display recent products with php in thumbnails [closed]

-2

I have a page and need to display in the index a 4 thumbs with the latest products registered in my bank mysql, I want to do this using php. If anyone can help, I appreciate it. My index uses bootstrap 3.

    
asked by anonymous 30.06.2016 / 14:31

1 answer

2

MySQL has a function called NOW () it returns the current date in the following format: '2016-06-30 10:27:34', you can save this value in the database in a column called data_cadastro , for example and use it as a reference.

If you want to use TIMESTAMP, you can do it as follows:

ALTER TABLE 'table_name' MODIFY COLUMN 'column_name' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

Imagining that we have now saved our field in the bank with the correct date, we can do a query as suggested by @Mayron Ceccon:

SELECT * FROM 'table_name' ORDER BY data_cadastro DESC LIMIT 4

Note that 4 at the end of the query refers to the number of records to return. You can read more about LIMIT in the official documentation of MySQL or in this beautiful post from Thiago Belem.

To make the request with jQuery as stated, you can read the .ajax method documentation on the official jQuery.

And to display the data you will need to loop through the result and add its contents to:

<a href="#" class="thumbnail">
  <img src="..." alt="...">
</a> 

Done this is just to send the content to the screen with jQuery itself.

Just a suggestion: Your question is totally incomprehensible!

    
30.06.2016 / 15:51