PHP - Retrive From Mysql By Date
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. Similar TutorialsI have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. So I would like to write a query on PHP but it doesnt exactly work the way I want it to work Code: [Select] Select * FROM user WHERE Rol_ID = 1 When I run this query it work on my sql, but when I try to enter this on a php page it just wont work. hi this is my code but I can't see the array in echo <table> <tr> <td> <h3> <?php //if the cart is empty show the message if (!$cart && !$_POST['item']) { echo "No cart available."; $cart = array(); } else{ //if the new item added to the cart let the customer knows if ($_POST['item']) { echo "Added to your cart: " . $_POST['item']; } } ?> </h3> </td> </tr> <tr> <?php //if the cart isn't empty show the cart if ($cart) { $cart[] = $_POST['item'];} foreach($cart as $key => $value) { echo'<td> <img src="images/'.$value.'.jpg" alt="'.$value.'" /> </td> <td> <form> <p> '.$value.' = <input type="text" size="2" name="number" value="1" /> </p> </form> </td> <td> <form method="post" action="update.php"> <p> <input type="submit" name="submit" value="Update This One Item" /> </p> <form> </td> <br />'; } ?> </tr> </table> Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated. hi all, mine http call : <script type="text/javascript"> var leadidarray =new Array(); leadidarray[1] = 100; leadidarray[2] = 200; leadidarray[3] = 300; leadidarray[4] = 400; leadidarray[5] = 500; var url = 'test.php?query=test&leadarray='+leadidarray; $.getJSON(url,function(data){}); <script> Now on the processing page i am getting $row = $_GET[leadarray] ; var_dump($_GET[leadarray]); or print_r( $_GET[leadarray] ); gives me values 100,200,300,400,500 but i want all that separate variables or all values in array so i can compare with another array, how can i do that? Does anybody know how to take the queried standard date format - 2012-04-02 for example - and print it to the page as April 2, 2012? Or at the very least, to switch to 04-02-2012? Trying to find some tutorials online. I want to have a feature on a website I'm building where the user can select rows from a MySQL table based on it's age. For example they could select a piece of content between 30-60 days old. I'm going to do this using the following sequel "WHERE article_date BETWEEN 2010-12-01 AND 2010-11-01" However I'm not sure how to make this work. If the date is 2010-12-12 what is the easiest way to subtract 30 days from this date? Thanks for any help. CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please What is difference between php date(); and mysql NOW() and what should be used in script? In php date I have 13:00h, and from MySql have 17:00h. Current date on my comp is 19:00h. So time difference in php is +6 hours, and in mysql is +2 hours. How to synchronize this dates for users??? im trying to crete a page that will search mysql for entrys from ??? days previous. ive not started on the php yet as i wanted to get the query done but im having a slight problem. date is in dd/mm/yyyy format. if i run this query SELECT * FROM `dsgi_serval` WHERE date >= '10/09/2010' it ONLY sorts by DD and not MM or YYYY, so anything greater than the 10th of the month shows regardless of what month. when i get to the php ill either do a drop down box with a preset number or days or a text box where u enter the number of days or even a txt box u enter the actual day u want to search from. im undecided which would be best. another problem i face with the php is how to tell the script to search from ? ?? when it says search from the past 3 days? <?php $date = date("d/m/y"); // todays date 04/12/2010 $_post= 3 days; // search from 01/12/2010 $date - $_post = $search; // 01/12/2010; $sql="SELECT * FROM $tbl_name" where date >= '$search'; echo the results ?> i no the above is not proper php but i hope it saya what im trying to do. Thanks hey guys the date stored in mysql is yyyy-mm-dd i need to convert it to do a string compare i have used the following $query = "SELECT * FROM booking where id=$sel"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $num1=$row['no_rooms']; $from1=$row['from']; $to=$row['to']; $sel1=$row['room_type']; $date = date('d-m-y', strtotime($from1)); } echo "$date"; it prints 01-01-70 can any1 tell me where is the error? thanks guys, im having a problem here thats making me crazy im making a system and i want to insert the current date in the mysql. I have the field called 'data' in the DB, but when i make the code to insert all the other fields, including the 'data', its work perfectly... unless that damn date! $query = "INSERT INTO news (id, titulo, mensagem, data) VALUES (NULL, '$titulo', '$mensagem', 'date(\"d/m/Y\")')"; whats wrong with that? its stores in DB as '0000-00-00'. hello with tis button i generate some statistics from mysql if(isset($_POST['sub1'])) { $result = mysql_query("SELECT servitoros1, COUNT(*) from history WHERE serv LIKE '%be%' group by serv1"); while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td ALIGN=\"center\">$cell<FONT></td>"; echo "</tr>\n"; } mysql_free_result($result); } but each record have datetime field!! so how can i set this display betwean 2 selectable datetimes e.g. from 2/2/2011 15:45 to 3/2/2011 23:59 i need a javascript date picker that will put a date in a text flied in the format of Y-m-d so that it can be posted to mysql also i need some kind of php to validite this Hello dear members, first of all sorry for my grammer i'm from Switzerland .
So now: I have a problem with php. I want to put out the date of a blogpost in this format dd:mm:yyyy instead of yyyy:mm:dd. I tried it a long time and used many different ways like: date, dateformat, strto etc. but at the and nothing worked for me. So here is a picture of the blogpost and i'll add the file with my compressd php code.
I'd be glad if you could help me
Regards Mr_Ironic I'm having trouble inserting a formatted PHP DateTime into a MySQL table. I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',2012-01-31)' at line 4 I get the error when I try to insert the date as a string from a DateTime object via: $insertDate = $date->format('Y-m-d'); As well as when I try to recast it as a date object: $insertDate = date("Y-m-d",strtotime($date->format('Y-m-d'))); I've also tried putting the date in ' ' 's and escaped " " 's. My insert query is: $insert = "INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('$partNum',$oQty,0,$aQty,'Excess',$price,$orderNum,'$tariffCode', '$location',$lineNum,$PKqty,$SPqty,'$allocDate');"; and the echoed output is: INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('0446535240 ',3,0,1,'Excess',163.89,66,' ', 'A0406E01',2,,,'2012-01-31'); Anyone have any ideas? Hello, I would like to order by date that contains day and month, like this: 14-3 Is this possible? Quote $sql = mysql_query("SELECT * FROM date WHERE online='1'"); Hi all I have an SQL database that holds dates in this format: yymmdd example: 110824 I am echoing the value: Code: [Select] <?php echo $showdata['date']; ?> How do I reverse the string so it shows 240811 ? Cheers Pete Hi, I'm trying to insert this $inceptiondate = date("Y-m-d 12:00:00"); to the database, the Y-m-d does make it to database, but the 12:00pm doesn't. Whenever it reaches the database, it becomes 00:00:00 Where did I got wrong? Thanks Hi Guys,
Been trying to make it that when I insert into Mysql at the moment it inserts like dd-mm-yy, however cause I'm in the UK i need it to do it in the UK way of dd-mm-yy I checked out some topics and found the STR_DATE_DATE however I've tried to use it in my mysql but cannot get it to work. Can someone help
$query="INSERT INTO job_scheduled (startdate, enddate, job_title, job_reference, job_description, job_postcode, job_city, customername, customer_email, status) VALUES ('".STR_TO_DATE($_SESSION["startdate"],'%d-%m-%y')."', '".$_SESSION["enddate"]."', '".$_SESSION["job_title"]."', '".$_SESSION["job_reference"]."', '".$_SESSION["job_description"]."', '".$_SESSION["job_postcode"]."', '".$_SESSION["job_city"]."', '".$_SESSION["customername"]."', '".$_SESSION["customer_email"]."', 'Provisional')"; |