PHP - Using Explode() Or Str_split() To Break Apart A Datetime Data Type
I am using a query to select everything out of a table in to an array. I have 4 fields as follows name, email, comment and datatime. What i want to do is use one of the stated function to grab the datetime elements and split them at the break point, but i am displaying more than one record with in the table, i think this is were i am fucking up.
for example i tryied this: Code: [Select] $commentsTable = "comments"; $comments = "SELECT * FROM $commentsTable"; $commentResults = mysql_query($comments); $commentRows = mysql_fetch_array($commentResults); $dateTimeSplit = explode(" ", $commentRows['datetime']); <?php while($commentRows = mysql_fetch_array($commentResults)){?> <div id="comments"> <div id="CommentWrapper"> <div id="comment"> <div id="UserComment"><? echo $commentRows['comment'];?></div> // here is were am having the problem!!! <div id="PostDateTime"><i>Posted: </i><? echo $dateTimeSplit['0'];?><i> Time: </i><? echo $dateTimeSplit['1'];?></div> </div> </div> </div> <?php } mysql_close(); ?> any sudgestions? Similar TutorialsHi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318249.0 SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype Hi all . In my scripts , there is a textarea that allow user to enter multiple phone number , message and date . If there are 3 phone numbers in textarea , how can I insert 3 of them into sql with the same data of message and date? Such as : phone number : 0102255888,0235544777,0896655444 message:hello all date:10/10/2011 and when it's insert into table , it will become: 1. 0102255888 | hello all | 10/10/2011 2. 0235544777 | hello all | 10/10/2011 3. 0896655444 | hello all | 10/10/2011 Here is the code I tried , but it will just save the last phone number . Code: [Select] $cellphonenumber = explode(',', $_POST['cellphonenumber']); $message = $_POST['inputtext']; $date = $_POST['datetime']; foreach($cellphonenumber as $value) { $sql="INSERT INTO esp( Recipient , Message , Date) VALUES ('$value','$message','$date')"; } mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated."; Any hints or advices ? Thanks for every reply . Dear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! If I explode a string well using a substring when I implode that substring is now missing. for example. Code: [Select] $exploded = explode("[MAC]",$data); $data = implode($exploded); Now [MAC] would be missing in the $data string. any way to get around this? I am getting an error on line 3 for the original code, so I need help there, but what I do have a question on is this: http://kaboomlabs.com/PDI/test2.php Code: [Select] <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) $result = $mysqli_query("SELECT * FROM comp"); echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}</option>\n"; } echo "</select>\n"; $result_close(); ?> What I am attempting to do is two fold. 1. Using PHP create a pull down menu that grabs data from the database. 2. Have something in where after line three there is a dotted break, and then the rest of the list is shown. There are over 150 entities that go into this database, so the top 3 are going to be the most used, the rest are going to be in alphabetical order. Now the database has a auto-increment numbering system, the company name, address, phone number, and email if possible. I only want it to show the company name. Is this possible at all? hi guys, in my form i need to insert an ID which is 5 digits number only. can anyone please tell me how can i check this before i insert? and also i need to check existing ID in my database. Coming from the world of Excel, I can easily format numbers as $1,500.00, or 27%. When I uploaded a large chunk of data into SQL to be read back through a table, the values all come out as exactly what they were uploaded as. For example, I have an SQL column set as Decimal(19,4) that I want formatted like currency, but which shows up as 1500.0000 in my table, or another column with type decimal(5,2) which shows up as 5500.0000, but which I want to show up as 55%. How do I do this?
Hi Masters,
I'll be making a big ticketing program with PHP and I cant decide what data type to use.
Thanks,
Marvin
Is this proper PHP... function setHeat(Building $b) { $this->hotness = $b->getInsideHeat(); } That looks more like Java to me. I thought you didn't define data-types anywhere in PHP?! TomTees I have a payment form with the following code... Code: [Select] <!-- Expiration Month --> <span class="group"> <label class="innerlabel" for="expMonth">Month</label><!-- --> <select id="expMonth" name="expMonth"> <option></option> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> </span> How is that data represented as far as Data-Type?? Is it treated as a String or an Integer?? How can I ensure that when I sent it to the Payment Gateway that it is treated as a Two-Digit value?? Thanks, Debbie Hello all, I just created this function that I want to use in CLi mode. It works perfectly in regular browser mode, but gives me this error on Cli mode if I do convertToCamelCaps('TEST STRING'); PHP Catchable fatal error: Argument 1 passed to convertToCamelCaps() must be an instance of string, string given in file... if (!function_exists('convertToCamelCaps')) { function convertToCamelCaps(string $string, $initialCaps=FALSE) { if ($words = explode(' ',$string)) { foreach ($words as $index => &$word) { $word = strtolower($word); if($index==0 && $initialCaps===FALSE) { continue; } $word = ucwords($word); } return implode('',$words); } return FALSE; } } If I remove the string datatype requirement in the function before the function argument list, it works fine in CLi mode. hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! This code gives me 1969-12-31 18:33:30 Code: [Select] <?=date('d M Y', $val['Created']);?> and this one gives me 2010-11-04 03:52:54 WHICH IS THE RIGHT ONE - BUT i need to format as above. Code: [Select] <?=$val['Created']?> this happens on the same line of code. What is wrong? Hello All, I have the following code: Code: [Select] echo "<table width='615px' cellpadding='3' cellspacing='4' align='center'>"; echo "<tr>"; echo "<td align='left' width='150px'>"; echo substr($row['date'],0,11); echo "</td>"; echo "<td align='left' width='465px'>"; echo $row["food"] ; echo "</td>"; echo "</tr>"; echo "</table>"; And this outputs: Apr 4 2011 Chicken Ceasar Salad, Garlic Toast, Cloddhoppers, Applesauce, & Milk (etc.) How can I add "Mon" in front of "Apr 4 2011"? thanks! Hey, does anybody know a good function, where I can have the trendy "time ago" functionality?
A good tutorial would be cool, too.
I would be using the datetime function off MySQL.
Hi, I'm a newbie here, and with PHP, and need some help with the datetime display. I am wanting to utilize old Naval comms DTG (datetimegroup) format which is DDHHMM 3-digit Month 2-digit year. The DDHHMM = Day (01 - 31) HH (hour 01 - 24) MM (minute 00 - 59) What I need to do is to add the letter Z (meaning GMT, ZULU) like thus DDHHMMZ FEB 11 How can I go about inserting that Z into this? Tks in advance for any assist Basically I am using DATETIME to store the time in which a row was input. Format - 2010-11-13 21:31:53 How would I get the current time of page load and compare it to the database row "2010-11-13 21:31:53" then output the difference. Example $sqlresult = 2010-11-13 21:31:53; $currentTime = (GET CURRENT DATE+TIME = (2010-11-13 21:31:55) ); Output - This was posted 2 minute's ago. Thank you in advance. Any help would be greatly appreciated. |