Yohanne Posted August 15, 2015 Share Posted August 15, 2015 Hi coders, This is not my actual table, but this is what im looking to do in my data, to display horizontal like image below. any body can help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/ Share on other sites More sharing options...
Barand Posted August 15, 2015 Share Posted August 15, 2015 see this thread - similar problem with solution http://forums.phpfreaks.com/topic/297720-php-matrix-table/?do=findComment&comment=1518791 Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/#findComment-1518895 Share on other sites More sharing options...
mac_gyver Posted August 15, 2015 Share Posted August 15, 2015 (edited) what have you tried? because the fun part of programming is in actually seeing code that you wrote produce the result that you want. your dates should be in a yyyy-mm-dd format (with leading zeros in the mm and dd) so that you can sort them. if you want to display them as m/d/yyyy, you would do that when you display the results. i would loop over the result (which should be sorted by the country name to give output in the order that you want) from your database query and produce two arrays. the first array gets all the dates. the second multi-dimensional array holds the data, using the country as the index for the first dimension, the date as the index for the second dimension, and the total as the stored data value. use array_unique() on the first array, then sort that resulting array. this will produce an array of unique dates in ascending order for producing the heading and for accessing the data under those headings. to produce the result, loop over the second array's first dimension (country), outputting the country name as the label for the row each time it changes. then, loop over the first array, and use each date to access the data, if any, for the current country for that date. if there isn't a value, output whatever indication you want (0, ----, n/a, blank). if there is a value, output the value. repeat for all countries being looped over. Edited August 15, 2015 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/#findComment-1518900 Share on other sites More sharing options...
Yohanne Posted August 18, 2015 Author Share Posted August 18, 2015 Hi, Thanks for all you responce, and i have new problem, i cant get current month and im using by the way, ODBC connection and using access 79 DB. WHERE Date between '8/1/2015' and '8/30/2015' but stil cant get all the date between. Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/#findComment-1519126 Share on other sites More sharing options...
mac_gyver Posted August 18, 2015 Share Posted August 18, 2015 afaik (after doing a little research) dates would need to be enclosed in #. give this a try - WHERE Date between #8/1/2015# and #8/30/2015# also, what is your date column definition? Short Date? 1 Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/#findComment-1519129 Share on other sites More sharing options...
Yohanne Posted August 18, 2015 Author Share Posted August 18, 2015 Thanks #mac_gyver, you gut it. and before i use text format and now i change into shot date. and you gut it. Thanks you. Quote Link to comment https://forums.phpfreaks.com/topic/297798-display-data-horizontal/#findComment-1519133 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.