LanceyDavid Posted December 23, 2010 Share Posted December 23, 2010 Hello, this is my first time on this forum and also a modest newb on php, but i heard alot of people i know visit this site to get help on php. So i have a question, i know how to submit a form to mysql, the question is how do i recieve each indivual data i submit with the form by date and display it in order by date. i would like to submit kind of a status up everyday similar to twitter but order it by date and have it look kinda like: July 5, 2006 This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. July 4, 2006 This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 23, 2010 Share Posted December 23, 2010 You order the results by the date (so that all rows having the same date will be together in the result set.) Then in your presentation code you 'remember' what the last date is and when the date changes value you output the new date heading. Then you output the data. This results in a date heading followed by the data for that date. Pseudo code - $query = " your query string here.. ORDER BY date"; // assumes that your date column is a DATE data type so that ordering by it will sort the dates $result = mysql_query($query); // check if the query executed without error and if it returned any rows here... // retrieve and process the data from the query $last_date = ''; // initialize to a value that will never exist as data while($row = mysql_fetch_assoc($result)){ // test for a new date and output the date heading if($last_date != $row['date']){ echo $row['date'] . "<br />"; $last_date = $row['date']; // remember the new date } // output the data (under each date heading) echo $row['content'] . "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1150789 Share on other sites More sharing options...
LanceyDavid Posted December 23, 2010 Author Share Posted December 23, 2010 I kind of understand it! "your query string here.. ORDER BY date" should be replace with the name of the column i give for the dates correct? and how will this look in a html table? or do i need to do that at all (i would like to give it style) Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1150793 Share on other sites More sharing options...
LanceyDavid Posted December 23, 2010 Author Share Posted December 23, 2010 *Bump* Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1150864 Share on other sites More sharing options...
LanceyDavid Posted December 26, 2010 Author Share Posted December 26, 2010 Does anyone have a clue? still wondering how to set it up in a HTML table format Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1151558 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2010 Share Posted December 26, 2010 Of course we have a clue how to output a table, but we are not here to write your code for you. What exact part of having php output the data in a table do you need help with? Did you attempt to do this with your actual query/database/columns? Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1151560 Share on other sites More sharing options...
LanceyDavid Posted December 26, 2010 Author Share Posted December 26, 2010 sorry, reading back i did sound kind of rude... but i understand fully on how to output it just dont understand how to read it and display it using a html table, im a noob when it comes to coding so i read through these forums as well as tutorials to get a full understanding. i guess u can say what i dont get is how to display it correctly for it to look as how i explained it prior.. thanks again guys, trully appreciate it (sorry im such a rookie in this) Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1151562 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2010 Share Posted December 26, 2010 So, did you use the pseudo code that someone posted to retrieve the rows from your database and output the date headings followed by the data under each date? That would be the first step. Outputting the necessary HTML tags to start/close the table and to put table headers <tr><th>...</th></tr> around the date headers and table rows <tr><td>...</td></tr> around the data would then only involve minor changes to the code to produce the following - <table> <tr><th>Header row1</th></tr> <tr><td>data row 1</td></tr> <tr><td>data row 2</td></tr> ... <tr><th>Header row2</th></tr> <tr><td>data row 1</td></tr> <tr><td>data row 2</td></tr> ... </table> Quote Link to comment https://forums.phpfreaks.com/topic/222505-retrive-from-mysql-by-date/#findComment-1151566 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.