
Psycho
Moderators-
Posts
12,160 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
Forgive me if I sound rude, but I cannot believe that statement. I can't understand how you would know how to use those functions yet not know how to use them to change the format of a date. The only possibilities I can think of are 1) you have no clue what you are talking about, 2) you have an idea but don't have the knowledge or initiative to do it yourself and are just wanting someone to do it for you, or 3) you're trolling. Let's break the problem down. You have a date such as 12-2-2013 and need to convert it to 2013-12-02. I already gave you two functions that you could use to solve this, right? You'll need to start with the original value of "12-2-2013". On which of those two functions could you use such a value? That will tell you which one to use first. Then, think about the output you would get with that function and how you could use it in the second function to get the result you want.
-
Yes, that is wrong. I You should use the database DATE type - and it will be stored in the format YYYY-MM-DD and you should not try to store it in a different format. You should convert the data formats between YYYY-MM-DD to whatever format you use for user output and back again. If you do not store the values as a DATE type you will be unable to use the built-in date functions of the database. Already answered above
-
Why did you feel the need to restate your question which I just answered? You need to convert the date from the user entered format to the appropriate format for the database. Databases use YYYY-MM-DD. You need to convert the format from DB to user presentation (and Vice versa) as needed in your code. I don't see any compare logic in the above code, so I think your confusion may be that the DB is automatically converting the dates for you - which you should not rely on. You should be converting the dates before inserting into your database.
-
Um, no. You are grouping the two records TICS TACS TOE --------------------------------------- 6 9 a 4 9 a And, in the query you using a GROUP BY and a SUM() function. The SUM() function will SUM the grouped records. 9 + 9 = 18.
-
Your link is broken or the content has been removed. You need to modify the date input from the user so it is in the proper format for using within a database query. Databases store the date in the format YYYY-MM-DD for several reasons. For example, it is agnostic to varying formats by regions. In the US we use MM-DD-YYYY, but in many other countries they use DD-MM-YYYY. Do not try to store dates as you read them, then you cannot use the data functions within your database. Just jchange the format before you use it. Look into strtotime() and date() functions.
-
Try $query = "SELECT year, amount FROM table_name ORDER BY year, amount"; $result = mysql_query($query); $data = array(); while($row = mysql_fetch_assoc($result)) { $data[$row['year']][] = $row['amount']; } //Post process the data foreach($data as &$year) { $year = '[' . implode(',', $year) . ']'; } $finalData = '[' . implode(',', $data) . ']';
-
A few thoughts. You should not store something such as "<img src="letter1.jpg" />". That is part of the presentation logic and should be handled outside the database layer. Here is what I would do: I would have two tables, one to store the words that will be displayed in the grid and another to record the squares that have been uncovered. The 'words' table would have three fields: column, row, & letter The other table, let's call it 'hits' would have just fields for column and row You could then query all the records from the two tables and build the table. Here is some sample code. I didn't test this as I wasn't going to build a database to test it, so there may be some minor typos, but the logic should be sound. //Query the words table and put results into array $query = "SELECT * FROM WORDS"; $result = mysql_query($query); $letters = array(); while($row = mysql_fetch_assoc($result)) { $letters[$row['row']][$row['column']] = $row['letter']; } //Query the hits table and put results into array $query = "SELECT * FROM WORDS"; $result = mysql_query($query); $hits = array(); while($row = mysql_fetch_assoc($result)) { $hits[$row['row']][$row['column']] = true; } $rows = 100; $cols = 100; //Create the table $output = "<table border='1'>\n"; //Create header row $output .= "<tr>\n"; $output .= " <th> </th>\n"; for($col=0; $col<$cols; $col++) { $output .= " <th>{$col}</th>\n"; } $output .= "</tr>\n"; //Create the main grid //Loop thorugh each row for($row=1; $row<=$rows; $row++) { $output .= "<tr>\n"; $output .= " <th>{$row}</th>\n"; //Loop through each column for($col=1; $col<=$cols; $col++) { //main logic to determine what to display in the square if(!isset($hits[$row][$col])) { //This square has not been revealed $square = "<img src='redsquare.jpg' />"; } elseif(!isset($letters[$row][$col])) { //Square has been revealed, but is not a letter $square = "<img src='whitesquare.jpg' />"; } else { //Square has been revealed, and is letter $square = $letters[$row][$col]; } $output .= " <td>{$square}</td>\n" } $output .= "</tr>\n"; } $output .= "</table>\n";
-
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
Again, no. This has nothing to do with PHPMyAdmin. Let me repeat again the following from the MySQL manual: This is how MySQL reports the events. Period. PHPMyAdmin is simply reporting the information reported by MySQL. I'm still at a loss as to why this is such an issue. PHPMyAdmin is an administrative tool. It sounds as if you want some sort of reporting utility to see/manage the events. So, as I've said a couple of times, you can create your own interface to display the data however you wish. -
how can i see or edit a stored array[] in mysql?
Psycho replied to unasemana's topic in PHP Coding Help
You're using serialize() on the data before you store it in the database, so I'm guessing you would use unserialize() on the data after you extract it. But, note that storing data in that manner will severely limit what you can do with it.- 2 replies
-
- array[]
- serialized
-
(and 3 more)
Tagged with:
-
@quickoldcar, Thanks for the heads up ont he mysqli version of real_escape_string. I've been using PDO and when I did a search on php.net for "mysqli_real" it didn't find that function (but it does if I use "mysqli real" - no underscore). Prepared statements is a different way of constructing and executing queries which adds a lot of benefits. For example, when using a prepared statement properly you do not need to escape the data to prevent SQL Injection. Plus, if you use a 'prepared' query it can be reused without much of the overhead in running the query the first time. The database does some processing of a query before it is run. With a prepared statement it does that operation once and you can pass different variable to run the query again without the same overhead. I'll admit I don't really understand all of the details - and don't care to. But, prepared statements is definitely the right way to go. But, it will take some relearning and is not something anyone could cover in a forum post. You can do a search for some tutorials or guides. Then if you run into problems post back here.
-
No need to loop through the array. Here's an easier solution - but I added a lot of validation logic as well: //Run array_map() with trim to trim all the values //Use array_filter() to remove empty values $firstnames = array_filter(array_map('trim', $_POST['firstname'])); if(!count($firstnames)) { echo "No data to insert"; } else { //Connect to DB $con=mysqli_connect("localhost","inputmultiplicad","inputmultiplicado","inputmultiplicado"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //Use array_map() with mysql_real_escape_string() to sanitize values $firstnamesSQL = array_map('mysql_real_escape_string', $firstnames); //Implode the values into a string for the query $values = "('" . implode("'), ('", $firstnames) . "')"; $sql = "INSERT INTO input_field (firstname) VALUES {$values}"; if (!mysqli_query($con, $sql)) { die('Error: ' . mysqli_error($con)); } //Output success message echo count($firstnames) . " record(s) added"; //Close DB connection mysqli_close($con); ?> EDIT: I just noticed you are using mysqli - so you can't use mysql_real_escape_string and I don't think there is a comparable function for mysqli. You should instead use a prepared statement and insert each record individually. Prepared statements will alleviate a lot of the overhead with running queries in loops. Although, if you would be running hundreds of record at once even that needs to be considered.
-
Is your site the "site.com" in the example? So, what you are really saying, is if someone tries to access a page - other than the index - you want to verify their referrer status correct? If you were to include the index page then you could create an infinite loop (although the header redirect might solve that). I will add the following to dalecosp's response: You should store the white-listed value in a database. Much easier to do a SELECT query on a value (or partial value) than looping through an array. Plus, you will likely want to build the functionality to include sub-domains by default. So, you will pull the referred domain apart to just get the root domain and the TLD. Plus, you should only run this logic the first time the user hits your site in a session. Once you have verified that they are allowed to navigate to other pages, then you should set a session value. Then, check that first on every page load. If OK, then continue on. If not, then use the logic to check the referrer.
-
Using Localhost in some other system - WAMP
Psycho replied to durgaprasadcs's topic in Apache HTTP Server
http://[iP_Address_Of_Computer_A]/ You may need to open the firewall on Computer A to allow the remote connection. -
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
There is nothing for you to fix. It is working as expected. I provided a link to the "bug" report and an excerpt of the response to that bug - which stated they were updating the documentation. Did you even take 5 minutes to look up that documentation? I'm not trying to be an ass, but the information I provided should have made it clear that this had nothing to do with a mis-configured setting. If you had looked up the update to the documentation that was referenced in the earlier post you would see why it is correct behavior. So, all events are scheduled based upon UTC time. After reading the above, it makes perfect sense, but it may not be blatantly obvious. You first need to understand timestamps. A timestamp represents the number of seconds since the Unix epoch (Jan 1, 1970 midnight). It is the number of seconds in UTC time. So, a particular timestamp for my would represent March 3rd, 2014 10:45 AM. But, that exact same timestamp would represent March 3rd, 2014 11:45 AM to you because you are 1 hour ahead of me. A timestamp is different than a datetime record in the database. A datetime would be used for something like recoding business hours. If a chain of stores exists in multiple timezones, you might store a single start and end times for hours of operations on a particular day. On that day, all the stores will open at 10:00AM (without any respect to the timezone). So, with that in mind, the events in MySQL are scheduled using a timestamp. However, it is always based on UTC rather than the servers local timezone. And, that makes sense. Let's say you have an event that should run every 30 minutes and the server is located in the Eastern timezone (UTC-5). So, every 30 minutes that event is executed. Then after an event is executed at 10:00AM the next execution would be at 10:30AM. Then assume at 10:15 AM the server's local timezone is change to Pacific time (UTC - 8 ). The server's local time would be 7:15AM. If it used its local time for the events it would think it did not need to run the event for another 3 hours and 15 minutes. I really don't understand why this is such an issue. You want the event to run every minute, so what is the fixation on what timezone the events are displayed in. As I said before, if you don't like it, build your own page to display the event details and changing the displayed time to your liking. -
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
As I already provided, the notes in the bug state they don't plan on fixing it. It really isn't a bug. In the database, timestamps are not stored specific to a timezone. Typically those records are modified on-the-fly when you query the database for those values based upon the timezone of the server. But, if you were to have an application that is used by users world-wide you can change the behavior at run-time so you can have the data returned based upon the user's timezone. This allows you to show data appropriate to the user. For example, if you have a system to record transactions and you make a new transaction at 10:00AM, I should see that transaction in the system as having occurred at 9:00AM (I'm in central time). Otherwise, I might see transactions as occurring in the future. I'm not 100% sure, but I believe all the timestamps are actually stored in UTC. It's not like it is something that is exposed to users. If it really bothers you, build your own page to display that data and have it modify the time when it is displayed. -
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
Google. I searched for "PHPMyAdmin Events UTC". The third result showed a snipped of content relating to UTC time so I clicked it. On that page was a link to the first page I provided. After I posted that I went back to the page and saw a link at the bottom to "View thread with replies". That page only had the original post and two replies. The last one was a guy reporting that it was a bug and linking to the bug report (which was the second page I provided). Took all of about 5 minutes or less. -
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
I don't know. Maybe the PHPMyAdmin page for the events was specifically coded to display the time in UTC. EDIT: I didn't read the article, but found this wiki item: MySQL What would lead the event scheduler to assume UTC? EDIT #2: Apparently it is a bug which has already been reported: http://bugs.mysql.com/bug.php?id=17835 But, it won't be fixed -
After you set up the category table you will need to do the following: 1. For the existing form above you would create a process to query the category table to dynamically create the select options. If the form will be used to edit existing records, then you will need to build that process to set the selected value based on the current record. 2. For the pages that display the records, you should already have a query to get those records. You will want to change those queries to JOIN the category table so you have the name of the category. Here is an example SELECT messages.name, messages.message, categories.category_name FROM messages JOIN categories ON messages.category_id = categories.category_id 3. Create a management page for the categories. Since the list will be very short I would just have a single page to edit all of the categories at one time. Just create a form with an input field for each category name. The input field could look something like this: <input type="text" name="category[{$idFromDB}]" value="{$valueFromDB}" /> The name will be an array and the id will be the numerical primary key value for each category. Then when the page is submitted, loop through each record in the array to get the ID and the value and update the records in the database.
-
That format works for me. Are you getting errors? I didn't do a DB query, but I ran the following and got the expected results for($i=0; $i<5; $i++) { $message = $message.<<<MESSAGE <h3>title{$i}</h3> <p>location{$i}</p> <p>subject{$i}</p> <hr> MESSAGE; } echo $message;
-
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
Well, UTC time is 5 hours behind New York. I was guessing it was maybe the time being returned in UTC instead of the local time. But, that should display a 5 hours time difference. So, I don't have anything else to add at this time. Sorry. -
mysql event last executed time incorrect by 6 hours
Psycho replied to kathygriffin's topic in MySQL Help
Sounds like a timezone issue. Where are you seeing that the execution time is wrong? Based upon my understanding that query should fail because you are trying to set an event to start in the past. -
Are you trying to create timers that only exist for 15 seconds? I really have no idea what you are trying to accomplish, but if you are creating timers that only start when the page is called I'm guessing that the delay between when the PHP page is called and the HTML page finishes loading is part of (or all of) that 3 second delay. Maybe you should explain EXACTLY what you are trying to accomplish
-
As I stated previously I made the function to output HOURS:MINUTES:SECONDS If you want just minutes and seconds then use this: function formatTimeDiff(diffVal) { total_seconds = Math.round(diffVal / 1000); if(total_seconds < 1) { return "Complete"; } seconds = total_seconds % 60; total_seconds -= seconds; minutes = total_seconds/60; return minutes+':'+seconds; }
-
Well, you are doing it wrong. You should store date values as dates in the database and not a PHP timestamp. But, it doesn't matter, you can still translate those integers into a proper datetime string using the PHP date() function. I've already provided a fully working JavaScript example and followed it up with some sample PHP code to generate the necessary client-side markup. You need to stop thinking about using PHP to calculate the time left. You need to do that on the client-side if you want it to be real-time. All you need from teh server is the list of events and their end time. Then process into the necessary code for the output to the client.
-
I assume you have a list of datetimes you are retrieving from the database, which should be in the format YYYY-MM-DD HH:MM:SS. You would iterate through those to create the JS array and the divs for the output. $timersJsArray = "var timers = new Array();\n"; $timersDivOutput = ''; $i = 0; while($row = mysql_fetch_assoc()) { $timersJsArray .= "timers[{$i}] = '{$row['endtime']}';\n"; $dateDisplay = date('F j, Y, g:i:s a', $row['endtime']); $timersDivOutput = "Timer {$i}:<br> End Date/time: {$dateDisplay} <div id='timer[{$i}]'> </div><br>"; } The output $timersJsArray within the JS block in the head of the document and $timersDivOutput wherever you want them to display on the page.