-2
I have a page and I need to display at index some 4 Thumbs with the latest products registered in my mysql database, I want to do this using php. If anyone can help thanks. My index uses bootstrap 3.
-2
I have a page and I need to display at index some 4 Thumbs with the latest products registered in my mysql database, I want to do this using php. If anyone can help thanks. My index uses bootstrap 3.
2
The 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_cadastre, for example and use it as 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 make a query as suggested @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 amount of records to be returned. You can read more about LIMIT in official documentation mysql or in this beautiful post by Thiago Belem.
To make the request with jQuery as said, you can read . ajax method documentation on jQuery’s official website.
And to display the data you’ll need to loop the result and add your content to the:
<a href="#" class="thumbnail">
<img src="..." alt="...">
</a>
This is done by just sending the content to the screen with jQuery itself.
Just a suggestion: Your question is totally incomprehensible!
Question or title?
Thanks buddy, you’ve helped enough!!
Browser other questions tagged php mysql crud
You are not signed in. Login or sign up in order to post.
Make a query in the database using "ORDER BY data_registration DESC LIMIT 4"
– Mayron Ceccon
The question is how to bring the database data and/or how to display it on the screen?
– Ademílson F. Tonato
Hello Mayron, users will not put registration date, so this has to be generated automatically and inserted in the bank.
– Bene
@Tonato, The doubt is how to generate the date of this registration automatically to do the query and how to bring this data up to the 4 Thumbs that will be in my index.html. Thank you.
– Bene
I don’t even think you know what you want :/
– Fábio
It is not because the question is not so well explained that you can say I don’t even know what I want friend!!!! Alias is a bit crazy that around here, say that the person does not know what he wants, if lack patience to interact do not answer!!!
– Bene