PHP - Php/mysql Date Output
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
Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=345631.0 Hi all I have a PHP script with the following var print $date; at the moment it is formatting the date like 03-24-2010 is it possible to get PHP to switch the date and month, so it looks like 24-03-2010 Thanks I am getting this error when I output a formatted date... Quote Warning: date() expects parameter 2 to be long, string given in I am using DATETIME. What do I need to do to fix things? Here is my code... Code: [Select] echo '<p class="commentDate">' . date($createdOn, 'g:ia') . ' on ' . date($createdOn, 'M j, Y') . '</p>'; Debbie I 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. hello I am trying to print a query out into a table that is grouped and styled by date. If the same date appears I want to style the row similar. Here is what I have: <table class="signup-sched"> <tr><th>signup date</th><th>Name</th><th>Notes</th></tr> <?php $myrows = $wpdb->get_results("SELECT `datefield-256` as signupdate, `your-name` as name, `your-email` as email, `your-message` as notes FROM wp_cc3_signup WHERE DATE_FORMAT(`datefield-256`, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m') ORDER BY `datefield-256`"); $sd = ''; if(count($myrows)){ foreach($myrows as $m){ if ($m->signupdate != $sd){ if ($sd != ''){ echo '<tr class="b"><td>'.$m->signupdate.'</td><td>'.$m->name.'</td><td>'.$m->notes.'</td></tr>'; } echo '<tr class="n"><td>'.$m->signupdate.'</td><td>'.$m->name.'</td><td>'.$m->notes.'</td></tr>'; $sd = $m->signupdate; } } } ?> </table> What am I doing wrong? Hello, Im trying to work out some code. On my site between Thursday 12th July and Sunday 15th July between the hours of 22:00 and 23:00 I want to display some code. I've done this so far, but am having trouble. Anyone please help? $the_date = date("H:i:s"); $timesep = explode(":",$the_date); // $hour = $timesep[0]; if (($the_date > 2010-08-12 && < 2010-08-15) && ($hour >= 22) && ($hour <= 23)) { //Code } 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. 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. Hi, Given below is the output of a field from a mySQL/php query: Product ID: 8457, Product Qty: 3, Product SKU: M-242, Product Name: DCE/DTE DB60 Crossover Cable - 1FT, Product Weight: 1, Product Variation Details: , Product Unit Price: 4.68, Product Total Price: 14.04|Product ID: 8800, Product Qty: 1, Product SKU: M-1038, Product Name: RJ45 8P8C Plug Flat Stranded 50pcs/Bag, Product Weight: 1, Product Variation Details: , Product Unit Price: 3.42, Product Total Price: 3.42|Product ID: 8940, Product Qty: 1, Product SKU: M-1385, Product Name: RJ11/12/45 Crimp Tool with Ratchet [HT-568R], Product Weight: 1, Product Variation Details: , Product Unit Price: 9.89, Product Total Price: 9.89 How can I add a <br> before every occurance of the term "Product" (without quotes). That would make the output legible. Should it be done client side, or server side. I can use help for both. Thanks in advance Hi Guys, I am a complete novice as you will soon notice. Can anyone suggest what I am doing wrong with this code. When I run the query in phpmyadmin it produces the correct answer. However when I try to output on my site with php it returns the result "Array". I am guessing I have oversimplified somewhere, aint got a clue how though Code: [Select] <?php include("configure.php"); // To grab the DB info $dbh = mysql_connect ("localhost", DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die ('<BR> - Could not connect to the database because: '.mysql_error()); mysql_select_db (DB_DATABASE, $dbh) or die(mysql_error( )); $query = "SELECT `options_values_price` FROM `rain_products_attributes` WHERE `products_id` = 526 AND `options_id` = 3 AND `options_values_id` = 3"; $result = mysql_query($query); if (!$result) { $message = "Error! Invalid Query: ".mysql_error()."\n Original Query: ".$query; die($message); } while($row = mysql_fetch_array($result)) { echo $row; } mysql_close(); ?> I have a mysql database that has your typical data in it, ie. name address, etc. The problem I am having is with the address. The address is setup as a varchar with 200 as the length and the data is street, city, st, zip on 1 line. I need to format the output with street on 1 line and city, st, zip on another. I cannot change input format because of the way the program uses the address string to fetch the lat and lng before it writes it to the database. Is there a way to add a line break or <br> to the address before it is written or change it after it is written using sql or php script or possible as I format the output? The street, city, st, zip are separated by commas in the record. Thanks in advance for all the reply's I have a question, something i SHOULD be able to do but i seem to be having a lapse in capabilities right now. Basically i have a MySQL database with a number of tables. One table called 'Users' and one called 'Scores'. Basically Scores are linked to Users by a UserID because a user may have multiple scores for different games and levels. Basically i want to output an overall scoreboard which adds up all the scores for each users and then outputs them in a big scoreboard. So for example USER - SCORE John - 20 Dave - 140 John - 70 John - 200 Dave - 200 Would output on the scoreboard as... Dave - 340 John - 290 etc.. Thanks guys. Hi, I'm trying to make a mysql output to a link so the name will be a link so when you hit this link you will get the full information of this mysql input. Can someone point me in the correct direction? Here is how i get the output from my mysql database into my table. Code: [Select] <td>"; echo $row['name']; echo "</td> if I'm outputting from mysql with this: Code: [Select] // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("test") or die(mysql_error()) ; //Retrieves data from MySQL $data = mysql_query("SELECT * FROM tickets") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo "<b>asset number:</b> ".$info['AssetNumber'] . "<br> "; Echo "<b>subject:</b> ".$info['subject'] . " <br>"; Echo "<b>notes:</b> ".$info['Notes'] . " <hr>"; } can I base the record it outputs somehow on this: Code: [Select] $value=""; $value = ProcessLargeText(GetData($data,"Asset Number", ""),"","",MODE_VIEW); if($mainTableOwnerID=="Asset Number") $ownerIdValue=$value; $xt->assign("Asset_Number_value",$value); if(!$pageObject->isAppearOnTabs("Asset Number")) $xt->assign("Asset_Number_fieldblock",true); else $xt->assign("Asset_Number_tabfieldblock",true); It's kind of like a job history so its getting records of job history from one table while the second piece of code is getting the asset details from a main table I'm trying to organize MySQL output in an HTML table based on individual states. Here is how the static HTML is currently displayed: http://www.u-s-s-a.org/breeders.html. Here is my working document: http://www.u-s-s-a.org/breeders.php. As you can see on the HTML page, each db row is organized into individual states. I'm only concerned about the US states, and not the countries outside of the US. Following is the code I've been working on (directoryoutput.php): Code: [Select] <?php require '/home/srob/public_html/u-s-s-a.org/config.php'; $connect = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('Cannot connect: '.mysql_error()); mysql_select_db ($dbname); $query = "SELECT * FROM directory ORDER BY flockname"; $result = mysql_query($query) or die ('Error, query failed.'); echo "<tr><td width='33%' class='style9'><p align='left' class='style12'><a name='AR'></a>Arkansas</p></td><td width='34%'> </td><td width='33%' valign='top'><div align='right'><a href='#TOP'><img src='returnTOTOPGRAPHIC/RETURNTOTOP.gif' width='113' height='21' border='0' align='absmiddle'></a></div></td></tr>"; $cnt = 0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ if ($cnt == 0){ echo "<tr><td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td>"; $cnt++; } elseif ($cnt == 1){ echo "<td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td>"; $cnt++; } elseif ($cnt == 2){ echo "<td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td></tr>"; $cnt = $cnt - 2; } } mysql_close($connect); ?> I'd appreciate any help on this code, including a more efficient way to parse out the MySQL db rows into 3 columns in the HTML table. Thanks in advance! Ryan I create a post just now but cannot seem to find it to add to it. Anyhow, I have 2 tables, I need to multiply qty from the one table to the mass from the other to get a total, which I have achieved with this code: $sql_total_mass = " SELECT jobs_assembly.assemble_qty, jobs.mass, (jobs_assembly.assemble_qty * jobs.mass) AS 'sum' FROM jobs_assembly LEFT JOIN jobs on jobs_assembly.jobs_id = jobs.id LEFT JOIN job_names ON jobs.job_names_id = job_names.job_id WHERE jobs_assembly.assemble_date = '$link_date' ORDER BY job_names.job_name, jobs.assembly "; $result_total_mass = mysqli_query($conn, $sql_total_mass); if (mysqli_num_rows($result_total_mass) > 0) { while($row_total_mass = mysqli_fetch_assoc($result_total_mass)) { echo $row_total_mass['sum'].'<br />'; } //while } //if Now I need to take all these totals and make a grand total. So basically add all the results from $row_total_mass[‘sum’] together and show it.
Hi guys.I am making a Query Analyzer in php which takes the query string inside a form and out puts the result table in that particular page.How do i output the notification by MySQL when you do a successful insertion of data into mysql.i want to know if there are any methods in php which gives you that such as "1 row affected","Query took 0.00sec".Thanks I currently have php code that outputs information from my database, but how do i make it also display the name of the fields beside each entry of the database? heres my PHP code: Code: [Select] <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:15px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo '<img class="image1" src="'. $row['images'] .'" />'; //image echo "Displaying record $i<br>\n"; echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['Property_type'] . "<br>\n"; // as above echo $row['Number_of_bedrooms'] . "<br>\n"; // .. echo $row['Purchase_type'] . "<br>\n"; // .. echo $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> thanks in advance |