Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is sprintf returning false here?

I am trying to work out why sprintf is returning false here. Can anyone shed any light?

sprintf( "select dog_name, date_format(meet_date, '%D %M %Y') as date, track_name, race_name, race_stakes, race_class, race_stakes, result_place, result_box, winner_name, winner_id, result_dog_trainer, race_distance
                                from dog
                                join result using( dog_id )
                                join race r using( race_id )
                                join meet using( meet_id )
                                join track using( track_id ) 
                                join (select dog_name as winner_name, dog_id as winner_id, race_id 
                                        from dog
                                        join result using( dog_id )
                                        where result_place = 1                                    
                                        ) t0 on t0.race_id = r.race_id
                                where dog_id = %d
                                    order by meet_date desc
                                limit %d", 12345, 50);
like image 570
Nick Maroulis Avatar asked Mar 23 '23 23:03

Nick Maroulis


1 Answers

You have too few arguments. If you use sprintf() with date_format, you should use two % like this:

sprintf( "select dog_name, date_format(meet_date, '%%D %%M %%Y') as date, track_name, race_name, race_stakes, race_class, race_stakes, result_place, result_box, winner_name, winner_id, result_dog_trainer, race_distance
                                from dog
                                join result using( dog_id )
                                join race r using( race_id )
                                join meet using( meet_id )
                                join track using( track_id ) 
                                join (select dog_name as winner_name, dog_id as winner_id, race_id 
                                        from dog
                                        join result using( dog_id )
                                        where result_place = 1                                    
                                        ) t0 on t0.race_id = r.race_id
                                where dog_id = %d
                                    order by meet_date desc
                                limit %d", 12345, 50);

here's the PHPFiddle

like image 60
Mark Avatar answered Apr 01 '23 22:04

Mark