Hello, Iam not an expert in PHP as I want to echo latest value from the table please help.

My table name is : sym_fruit

fileds name in the above tables are : id, fruitname, date

each day i will add new fruit to this table so the latest fruit name only need to print, if I didn't added any fruit name on a day i need to show a message "New fruit name was not added on today " in my table (sym_fruit) the date was storing like this ( 12/07/2018 10:14:43pm )
so each day added name are insterted to the table with autoincrument of ID , fruit name and date

I tried below code to ech but it was printitng this text : Array below is my code

$pname = $con->select("select fruitname from `sym_fruit` order by `id` desc ",false); ?>       

<?php echo $pname; ?>
1 Week
Discussion Span
Last Post by alan.davies

You are using DB abstraction - no idea what this "select" method returns - object, resource or array of arrays.
Let us assume its an array of arrays (either indexed or associative).

if( $pname ){
    print_r( $pname );

echo does not work for arrays.



below is my table screen shot, actually i want to show the last added fruit name on my website. If it can be print there based on the date I mean today is 13/July/2018 I haven't added any names there so I want to show an meesage "New fruit name was not added on today " if in the table there was any fruit name added on today date (13/July/2018) that need to print. If any one know how to do it that will be helpful



Any one can help me on this it was very urgent..


I believe the general SQL you need is something like:

"SELECT `fruitname` FROM `sym_fruit` ORDER BY `id` DESC LIMIT 1"

That will give you ONE record due to the "LIMIT 1" clause, however, tying it down to your date is a little trickier due to the format you've decided to use for your table. Generally, the format YYYY-MM-DD HH:MM:SS (or the numerical equivalent (YYYYMMDDHHMMSS) is used.

So one solution for this - there my be a better one would be:

"SELECT `fruitname` FROM `sym_fruit` WHERE STR_TO_DATE(`date`, '%d/%m/%Y') =  CURDATE() ORDER BY `id` DESC LIMIT 1"

So if no records returned - show negative statement, else you have your fruit and echo it in your string.

BTW - urgency is irrelevant - we are all volunteers and help when we can - we don't jump when prodded :)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.