OriginalBoy Posted April 2, 2008 Share Posted April 2, 2008 Hey, I have set up a mysql database with a date feature. I need this date feature to work so when it is submitted it will show the date it was submitted. Everything is done apart from this so I am very keen to get it finished. I made the table in phpmyadmin and now I do not know whats next. If its to complicated to explain in a post feel free to add me on msn steve@whitepixeldesign.com. Thanks Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted April 2, 2008 Share Posted April 2, 2008 Basically when ever the person has submitted whatever they need to submit, I suspect that you already have something that tells PHP, "Okay, the whatever is submitted now we need to execute this", if not, then post what it is you are trying to do and we would help you with that. As for the date in mysql, the mysql date format is as follows "year-month-day" i'll give you a little snippet below and all it does is show you how you would insert the date into mysql, and if you would like to show the date to users as "month-day-year" I will also include a function for that. Here we go, <?php $date = date('Y-m-d'); //I assume you know where to put the name of your table, and the row for the date $query = "INSERT INTO your_table (row_name) VALUES ('$date')"; mysql_query($query); ?> As for fetching, and displaying the date here's what I do. <?php //function to convert the date inputted //to the following format //month-day-year function convert_date($date) { $ex = explode("-", $date); $dates = "{$ex[1]}-{$ex[2]}-{$ex[0]}"; return $dates; } //echo the date $s_date = convert_date($your_date); echo $s_date; ?> Hope I explained fairly well, I am after all only 16 and not very good with explaining haha, if you need any help just let me know. Quote Link to comment Share on other sites More sharing options...
marklarah Posted April 2, 2008 Share Posted April 2, 2008 or in mysql use ......date = NOW().... Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted April 2, 2008 Author Share Posted April 2, 2008 But how do i get the code from the table i created in PHPmyadmin?? Quote Link to comment Share on other sites More sharing options...
marklarah Posted April 2, 2008 Share Posted April 2, 2008 So if you have in your table 3 rows...ID, (id) the date posted (p_date) and the content (content) to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); to display it row by row $result=mysql_query("SELECT * FROM example"); while ($row = mysql_fetch_array($result)){ echo 'ID - '.$row['id'].'<br>'; echo 'Date - '.$row['p_date'].'<br>'; echo 'Content - '.$row['content'].'<br>'; } try that >_> (adapt it of course) Quote Link to comment Share on other sites More sharing options...
marklarah Posted April 2, 2008 Share Posted April 2, 2008 http://uk.php.net/date Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted April 2, 2008 Author Share Posted April 2, 2008 So if you have in your table 3 rows...ID, (id) the date posted (p_date) and the content (content) to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); to display it row by row $result=mysql_query("SELECT * FROM example"); while ($row = mysql_fetch_array($result)){ echo 'ID - '.$row['id'].'<br>'; echo 'Date - '.$row['p_date'].'<br>'; echo 'Content - '.$row['content'].'<br>'; } try that >_> (adapt it of course) Do i need to make a new file or add it to an existing one? Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted April 2, 2008 Share Posted April 2, 2008 Originalboy if you would like to fetch only the date, use the way i showed you to fetch a date, if not and you would also like to fetch the time it was posted use the NOW() mysql function that marklarah had posted. Just an FYI. Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted April 2, 2008 Share Posted April 2, 2008 So if you have in your table 3 rows...ID, (id) the date posted (p_date) and the content (content) to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); to display it row by row $result=mysql_query("SELECT * FROM example"); while ($row = mysql_fetch_array($result)){ echo 'ID - '.$row['id'].'<br>'; echo 'Date - '.$row['p_date'].'<br>'; echo 'Content - '.$row['content'].'<br>'; } try that >_> (adapt it of course) Do i need to make a new file or add it to an existing one? That's just how you fetch the information include it in your current file and use variables to store the information and display it only whenever you need it. If that makes since? Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted April 3, 2008 Author Share Posted April 3, 2008 So if you have in your table 3 rows...ID, (id) the date posted (p_date) and the content (content) to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); to display it row by row $result=mysql_query("SELECT * FROM example"); while ($row = mysql_fetch_array($result)){ echo 'ID - '.$row['id'].'<br>'; echo 'Date - '.$row['p_date'].'<br>'; echo 'Content - '.$row['content'].'<br>'; } try that >_> (adapt it of course) Do i need to make a new file or add it to an existing one? That's just how you fetch the information include it in your current file and use variables to store the information and display it only whenever you need it. If that makes since? The point im trying to get to is where do i add the code i made the table in PHPmyadming now I keep getting a load of code but have no idea what to do with it and where to add it. Quote Link to comment Share on other sites More sharing options...
marklarah Posted April 3, 2008 Share Posted April 3, 2008 Wherever you want to display the results of your table, in a page, just make a new file with a .php ending, in between these tags: <?php ?> and then write the code i gave you, modified to your table. Post the column headings and we'll help you. Quote Link to comment Share on other sites More sharing options...
marklarah Posted April 3, 2008 Share Posted April 3, 2008 may help: http://tinyurl.com/h4uhn Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted April 3, 2008 Author Share Posted April 3, 2008 to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); What would go in the 'whatever' ? Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted April 3, 2008 Share Posted April 3, 2008 to upload, mysql_query("INSERT INTO example (id, p_date, content) VALUES(null, NOW(), 'whatever' ) ") or die(mysql_error()); What would go in the 'whatever' ? the 'whatever' area is for instance if you wanted a user to post stories the story variable would go in place of 'whatever' Quote Link to comment 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.