-
Posts
422 -
Joined
-
Last visited
-
Days Won
1
Everything posted by awjudd
-
How to get the last 30 days data from mysql database in php?
awjudd replied to angel1987's topic in PHP Coding Help
Are you using a DATETIME column to store the date or something else? ~juddster -
You can't make a default value of a variable. In order to do what you want you should change it to something like this: public static function is_valid ( $method = NULL ) { /* Check if it is NULL, that means just use $_POST */ if ( $method === NULL ) { $method = $_POST; } } That said the variable name is very misleading. If I read a variable named $method, I would think it would be something like 'POST' / 'GET' however, you are using it as the array to validate. So I would change that accordingly to make the code more readable. ~juddster ~juddster
-
You would replace that code with mine. ~juddster
-
Oops, sorry about that user typo Please mark this topic as complete ~juddster
-
1 - http://php.net/ereg - an old regular expression match (RTFM) 2 - It would either make your current else an else if OR it would just consume the body of your else statement 3 - They are automatically defined for you. You just change the variable you are reading from, from $_REQUEST --> $_POST else if ( isset ( $_POST [ 'button' ] ) { // Required field error echo 'Required fields are empty'; // Lets fine out which one(s) $nameError = ($_POST['name'] == '' ? true : false); $emailError = ($_POST['name'] == '' ? true : false); $enquiryError = ($_POST['name'] == '' ? true : false); } else { $nameError = false; $emailError = false; $enquiryError = false; } ~juddster
-
The query I provided and the one that you changed it to are two completely different queries. The one you changed it to does an ANSI JOIN without any conditions making it a CROSS JOIN. What part of my queries didn't work? Did they take too long to execute or what? I noticed a typo in my query: SELECT u.User_email, lt.last_time AS last_signed_in, r.last_time AS reminder FROM Users u LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY User_id ) lt ON u.User_id = lt.User_id LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY User_id ) r ON u.User_id = r.User_id ~juddster
-
About which comment that I made since there are three ... ~juddster
-
I would add in a check either with the ereg (deprecated - should be using the preg family of functions) to see if all of the required values have been set before attempting to send the email. If you want to keep it in your else, just put it in an if statement. For example: if ( isset ( $_POST [ 'button' ] ) ) { echo 'Required fields are empty'; /* Extra code */ } That said, you swap between $_POST and $_REQUEST. I would make that consistent because you don't want some things coming from the URL or a cookie and others from $_POST. ~juddster
-
Please remove all of the extra whitespace because nobody is going to read the code if they have to scroll down pages and pages to read it. ~juddster
-
Move the header function call to after the mysql_close call. This will ensure that it was successful before redirecting. ~juddster
-
You have MD5 as your password however, in your INSERT query you are using SHA1(CONCAT(UPPER('$usr'),':',UPPER('$var'))) to insert the encrypted password. You need to be consistent if you want to pull the data back. ~juddster
-
Using JOINs makes it insanely easy. SELECT r.ItemID, it.ItemTitle, SUM(r.Rating) AS mr FROM dd_rating r JOIN dd_items it ON r.ItemID = it.ItemID GROUP BY r.ItemID, it.ItemTitle ORDER BY mr DESC LIMIT 0, 4 I'm not sure why iblood isn't a fan of JOINs but that is just crazy. ~juddster
-
Something like this should work: SELECT u.User_email, lt.log_time AS last_signed_in FROM Users u JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY User_id ) lt ON u.User_id = lt.User_id JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY User_id ) r ON u.User_id = r.User_id Basically the problem is you are having is that effectively making a CROSS JOIN for the log table which is going to be bad ... Another approach is: SELECT Users.User_email , MAX(CASE WHERE lt.log_type = 3 THEN lt.log_time ELSE NULL END) AS last_signed_in , MAX(CASE WHERE lt.log_type = 12 THEN lt.log_time ELSE NULL END) AS last_reminder_sent FROM Users u JOIN log01 AS lt ON lt.log_usr = Users.User_id WHERE l.log_type IN ( 3, 12 ) Basically the first query will go against the log table and find the maximum log time for each user for the reminders and log in times and then just use that in the outside. This will be able to run quicker than yours is currently because each table will be returning up to 1 row per user. The second one which I think is a bit cleaner but could be slower. It is essentially just grabbing all of the rows where the log type is either 3 or 12 and then processing it in the MAX function (determining what to send) based on the log type. Does this make sense? ~juddster
-
By using JOINS instead of IN SELECT p.product_num FROM products p JOIN tconversions t ON p.product_id = t.to_product_id to_product_id JOIN products p2 ON t.fr_product_id = p2.product_id WHERE p2.product_num = '$product_num'
-
For the comments table join since it is a LEFT JOIN, if there are no matching results then it will return NULL. Because of that you should be adding your condition for the status on that table = in the ON clause instead of in there WHERE clause. Because if it appears in the WHERE clause it needs to find a comment to show up (you could just have the condition as: tblComments.comments_status = 2 OR tblComments.comments_status IS NULL). ~juddster
-
Have you indexed your tables? Have you run EXPLAIN on your queries to see how it is actually being run through the query engine? ~juddster
-
And by plugin I mean open source project / api. ~juddster
-
Try the stuff from their documentation with their use of children? Or better yet: $visitior = $visitor -> find ( 'td a', '1') -> innertext; I have never used this plugin before so it is just a guess. ~juddster
-
By having a LEFT JOIN and then following that up with a WHERE clause using where you are requiring a value of that field, you are removing the use for the LEFT JOIN. ~juddster
-
I would go one layer deeper where you are looking for 'td' and actually look for the 'a' tag. Then you would be able to grab the innertext. /* An extension to your code */ $visitor = $visitor->find('td','1')->find('a','1')->innertext . "<br>"; ~juddster
-
!= is does not equal, not /= That said, there is a very much an easier way of doing this ... /* Check if the dice and roll match */ if ( $roll == $dice ) { /* They do, congrats */ print "Great Job, You're Good!"; } else { /* They don't, too bad */ print "Wrong"; } /* Print the dice number */ print "<img src='dice" . $dice . ".png'>"."<br />";
-
Please use the [ php ][ /php ] tags for your code (minus the spaces). ~juddster
-
Please mark this thread as resolved if we have resolved your issue. If you have any other questions please feel free to drop by the IRC channel. I am on all of the time (sometimes AFK) but there is always someone to help. ~juddster
-
Which column? The amount columns? ~juddster
-
It may be a bit of a pain if you have lots of data in your database already to do the migration. But if you don't then it shouldn't be too bad. ~juddster