Jump to content

Psycho

Moderators
  • Posts

    12,145
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. One other note. The BETWEEN operator may not be working as you intend. When you have this due_date BETWEEN '2014-08-14' AND '2015-08-14' It will match all records starting at midnight (00:00:00) on 2014-08-14 to midnight (00:00:00) on 2015-08-14. In other words, anything on 2015-08-14 from 00:00:01 to 23:59:59 will NOT be included. Never mind. The due date is a DATE type and not a TIMESTAMP. So it will be inclusive.
  2. A few thoughts. I create my queries in a logical order based on how you want the data. In this case you are gathering data about resellers with the earnings being secondary. So, I would select from the resellers table first. It would work with what you have, but it makes more sense to me to switch it. Second, what if there are not records in the orders table for a particular reseller. Using a normal JOIN, as you have above, that reseller would not be included in the results. If you want ALL the resellers to be displayed (even if there are no order records to JOIN on), then you need to use a LEFT/RIGHT join. You would use a RIGHT JOIN with the order you have above, but it would be a LEFT JOIN if done in the reverse order (which makes more logical sense to me). Third, you are including other fields in the order table (besides the earnings field). But, you are grouping the records from that table to get the total. I would assume each order has a unique ID, status and earning value. So, including those fields and doing a GROUP BY will retain only one value from one of the fields that were group. This makes no sense. Either leave those fields out or include them and leave out the GROUP BY to get the total - you can get the total by adding the earnings field when processing the records. But, I'm guessing you really don't need those fields. Fourth, ideally you would not be using a textual value for Order Status and instead use a numeric identifier (which could map to another table with the textual values). Using a LIKE clause to filter the records is very inefficient. Lastly, the SELECT list contains the field r.reseller_id, which does not exist. Based on the table schema provided it would be r.id Try this: SELECT r.id, r.reseller_name, r.reseller_surname, r.reseller_email, r.reseller_phone, r.reseller_commission, r.reseller_vat_number, -- o.id, o.reseller_earnings, o.order_status, SUM(o.reseller_earnings) as total FROM resellers as r LEFT JOIN orders as o ON r.id = o.resellers_id WHERE o.due_date BETWEEN '2014-08-14' AND '2015-08-14' AND o.order_status LIKE '%Order Completed%' GROUP BY r.id ORDER BY total DESC
  3. What do you mean by "Is it possible to see the result of left join of two tables(without on clause)?" What do you expect to get without an ON clause for a LEFT/RIGHT JOIN? Why don't you explain what you are trying to achieve?
  4. Well, scootstah's 'creative' solution aside, both mine and Barands's solutions would work. If you review those two you would answer your question above.
  5. The following solution protects against an item not existing in the list, but does not contain logic to prevent an infinite loop if the values were to contain such a problem <?php $paths = array( 'A' => 'B', 'B' => 'C', 'C' => 'D', 'D' => 'A' ); function getPaths($fullStart, $fullEnd, $paths) { $pathListAry = array(); //Return array $pathStart = $fullStart; //function var $pathEnd = false; //function var while($fullEnd != $pathEnd) //Run loop until full end is found { if(!isset($paths[$pathStart])) { echo "Error: No path starting with $pathStart"; return false; } $pathEnd = $paths[$pathStart]; $pathListAry[$pathStart] = $pathEnd; //Set start to current path end point $pathStart = $pathEnd; } return $pathListAry; } //Run solution $start = 'A'; $end = 'D'; $thePaths = getPaths($start, $end, $paths); //Output results echo "Starting from $start and ending at $end : <br><br>\n"; echo "<pre>" . print_r($thePaths, true) . "</pre>"; ?>
  6. I've never used getElementByID() recursively like this var mname = document.getElementById('addform').getElementById('machine_name'); Is there a reason why you are referencing the form using getElementById() then trying to reference the 'machine_name' elements using getElementById() from that? Why not just directly reference the 'machine_name' element using var mname = document.getElementById('machine_name'); Also, the function doesn't make sense. You are getting the value for Target, but then simply returning returnVal - which is false. I'm guessing this is not complete. And, there will also be a failure on this line since 'f' is not defined var target = f.getElementById('target').value;
  7. The answer is it depends. I know a good bit about VBScript as opposed to Visual Basic, but it is mostly transferable. If you only need to know if the body contains the word "cash" you would still need to account for variations such as "Cash", "CASH", etc. So, I would do the following: Convert the body to all lower or upper case characters. Then check for the target word. That is the simplest solution, but has one downfall. If 'cash' is contained in another word as opposed to being its own word it would still provide a match. To work around that you would need to use Regular Expression which is more complicated. Based on your actual need you may need to go that route. Note that if this is for some type of spam detection process you will likely get a lot of emails falling through the cracks since they will use other characters to get around detection, e.g. "ca$h". So, you could use the LCase function to convert the body to all lower case and then the InStr function to see if your target word is contained in the content. Here is some mock code: VAR bodyText = LCase(mail.body.text) IF InStr (bodyText, "cash", vbTextCompare) Then ' "cash" does exist in the body Else ' "cash" does not' exist in the body End If
  8. Psycho

    No word wrap?

    Yep, I was right. The HTML is invalid. On every row in your results you have an opening FORM tag and a a radio button input. But, you don't close the form! instead there is a single closing form tag after all the records (and multiple opening forms) are created. However, something else is wrong as well. Even on a page with just one record (where there would only be one FORM opening tag, it still doesn't work. But, there are so many other problems it's not worth my time to try and troubleshoot. The HTML output is a mess. Many problems should not have any functional implications, but it all adds up. Here's one tip for you: In the code to produce each row of verses, you are defining the width for each column in the TD element. It would be much simpler to just define the width ONE TIME when creating the header row. Less code to clutter the logic and less output to send to the browser.
  9. Psycho

    No word wrap?

    You misinterpreted my comment. I didn't say there was no closing TD tag. I said there was no closing bracket for the opening tag. Line 133 above is this: It should be this: As for your new problem, I doubt it is a CSS issue. It is likely an HTML. When I ran your page through an HTML validator, there were plenty of errors. I recall there was one or more about the FORM tags.
  10. Psycho

    No word wrap?

    I believe this is your problem: ol,ul,li,h1,h2,h3,h4,h5,h6,p,span,td,div { margin:0px; padding:0px; line-height:0px; <== REMOVE THIS list-style:none; } It makes no sense to my why you would globally apply those style properties to all those elements anyway. For example, what does list_style have to do with header tags?
  11. Your problem is that the variables used to identify the index contain values that do not exist as indexes in those two arrays. Either the indexes in one or both of those arrays are not sequential or the max limit ($Counter3) is higher than the indexes in those two arrays. When dealing with arrays, you should almost always be using the foreach() loops to iterate through the values, as Ch0cu3r shows, rather than trying to programatically determine the indexes to use. I'll add some more suggestions: Give your variables meaningful names that give an indication as to what they contain. Otherwise, you spend too much time trying to figure out what is what - especially when you have to go back to some code in the future. Separate your logic (PHP) from your presentation (HTML). This makes your code much more maintainable and flexible. In this case, rather than stick PHP code to create the options between the <select> tags you could put the PHP code at the top of the page and store the output for the options in a variable. Then just include an echo statement in the HTML where the <select> tags are. Also, with all due respect to Ch0cu3r, I would suggest including line breaks (and even spacing) in the HTML output using \n and \t. It makes it much easier to debug issues in the HTML code. Example: <?php //Array of menun groups and options $menuOptionsAry = array( 'Drinks' => array( 'Tea', 'Coffee', 'Orange Juice', 'Apple Juice' ), 'Food' => array( 'Toast', 'Ham Sandwich', 'Chicken Soup', ), 'Desert' => array( 'Ice Cream', 'Chocolate Moose', 'Jelly' ), ); //Create the default value for the menu options list $menuOptions = "\t<option value='None'>No Component</option>\n"; //Create the dynamic values for the menu options list foreach($menuOptionsAry as $menuGroupLabel => $menuGroupValues) { $menuOptions .= "\t<optgroup label='{$menuGroupLabel}'>\n"; foreach($menuGroupValues as $menuValue) { $menuOptions .= "\t\t<option value='{$menuValue}'>{$menuValue}</option>'; } $menuOptions .= "\t</optgroup>\n"; } ?> <html> <head> <title>Sample Page</title> </head> <body> Select a menu item: <form> <select name="menu"> <?php echo $menuOptions; ?> </select> </form> </body> </html>
  12. Psycho

    No word wrap?

    This would not be a PHP or MySQL problem. It would be a problem in the HTML/CSS. Posting the server-side code only complicates our ability to help you. Please provide the output that is causing the problem. If you provide a link to a page with the problem, it would be helpful to work with the CSS code to debug. But, right off the bat I see invalid HTML code. On line 133 there is no closing greater than symbol for the TD tag. Also, the value for the input on line 137 should be enclosed in quotes. Also, why all the lines of code to clear the mysql results before you close the table? It's not invalid, just not logical in my opinion.
  13. You are trying to use ORDER BY in two different ways - one to get the last three records that have been added and another one to sort them for display purposes - you can't do both concurrently. You can use a subquery to get the last three records and an outer query to sort them for display purposes SELECT * FROM ( SELECT Id, zone, xtime, xdate, temp, status FROM temp_log WHERE zone LIKE 'Unit%' ORDER BY Id DESC LIMIT 3 ) unitResults ORDER BY zone
  14. @obodo, I'm not sure what the purpose of your code is, but it does not match reality. I'm sure there are some exceptions out there, but how you are calculating the pay periods is not what is done in the real world. Companies that pay once a month, don't set the pay periods up to be 30 days apart. They set up the payday to be on the same numerical date each month. For example, payday would be on the 5th of each month. However, they would also have rules to account for when the 5th lands on a weekend or a holiday. For paydays that are every every week, or every two weeks, those would be on the same day of the week every week (or two) with adjustments for holidays. Note that with this type of pay periods, there will be months with five paydays (for weekly) or three paydays (for bi-weekly) For paydays that are twice a month, they are set up the same as the monthly pay period. They will be on two specific dates each month (e.g. the 1st and the 15th). The logic you are using is not accurate and is more complicated than reality, IMHO.
  15. Except Barand hasn't posted in this thread . . . so I assume you are talking about the code I posted. Vapor, you posted a problem and we took the time to provide solutions. Now you are asking us to analyze some other code to determine what is better and "clean & secure". Sorry, but I'm not going to take the time to do that. The code I posted works with the content on the page provided at the time I wrote it. If that content changes (specifically the format), I can make no guarantees. As to how you should display the output, that I leave to you. That is where you definitely need to worry about ensuring the code will not create security problems (e.g. XSS). That can be resolved using htmlentities() as one solution. But, how you create the output (CSS tables, etc.) is up to you. This forum is about helping people with code they have written. It would be nice to see you at least make an attempt as opposed to just writing everything for you.
  16. Here's a function to extract the data that appears to work for the data. You can then iterate through the array to create the content that you wish <?php function getData($url) { $output = array(); $content = file_get_contents($url); $lines = preg_match_all("#<a[^\n]*\n#", $content, $matches); foreach($matches[0] as $line) { if(preg_match("#<a[^>]*>([^<]*)</a> \"([^\"]*)\" \(W\) GUID\=(\d*)[^\[]*\[([^ ]*) ([^\]]*)#", $line, $match)) { $output[] = array( 'id' => $match[1], 'image' => "{$url}pb{$match[1]}.png", 'username' => $match[2], 'guid' => $match[3], 'date' => $match[4], 'time' => $match[5] ); } } return $output; } $url = "http://74.80.133.251/7778/"; $data = getData($url); echo "<pre>" . print_r($data, 1) . "</pre>"; ?> Here is an example of part of the output Array ( [0] => Array ( [id] => 001646 [image] => http://74.80.133.251/7778/pb001646.png [username] => -=D3G=-RotGM [guid] => 00000000000000076561198133386615 [date] => 2015.06.25 [time] => 17:20:36 ) [1] => Array ( [id] => 001647 [image] => http://74.80.133.251/7778/pb001647.png [username] => -=D3G=-Icey842 [guid] => 00000000000000076561198091035675 [date] => 2015.06.25 [time] => 17:22:18 ) [2] => Array ( [id] => 001648 [image] => http://74.80.133.251/7778/pb001648.png [username] => budsanonymous [guid] => 00000000000000076561198188792511 [date] => 2015.06.25 [time] => 17:23:28 ) Note that using RegEx is not very efficient. So, you may want to cache the data and only update if the cache is older than some time period.
  17. The code looks fine. Is the page being processed through a web server with PHP enabled?
  18. So, each user gets to determine the start date? Is the date counter based on calendar days or 24 hour periods from when the user starts the counter? For example, if the user starts the counter at 10:00AM today, does it move to the next number each day at midnight or 10:00AM? You will need to store the date of when the user clicks to start the counter. You can either do this with a cookie (which the user can reset) or you can do it in a database (which requires the user to log in to see the current counter value). Once you have a saved value for the start of the counter, you just need to add some logic to count the different between the start of the counter and the current day. That will depend on where you store it and when the counter should be incremented (midnight or same time as originally set). If you store the start date/time in the database you would want to do the calculation there: DATEDIFF(). If you do it in a cookie, you will need to do the calculation with PHP: DateTime::diff
  19. I really have no idea what you mean based on your description. Here's some code that "may" help you. $numberOfDays = 20; for($d=0; $d<$numberOfDays; $d++) { $dayNo = $d+1; echo "Day {$dayNo}: " . date("M j, Y", strtotime("+{$d} days")) . "<br>\n"; }
  20. You say you found the solution - but there are multiple solutions. My preference is to put any files that shouldn't be directly accessed outside of the public folders. Then you don't have to worry about folder permissions or putting logic into the files to prevent access.
  21. mac_gyver provide a lot of good info, but the above was something that you should pay particular attention to as the problem may not have anything to do with bots. If I understand his comment, the page would send an email just from accessing the form - i.e. so submission would be needed. If that is the case, you should wrap all the logic to receive the form data and process it within a condition that actually checks if the form was submitted.
  22. FYI: It appears the back tick and the W got combined into a single character with a dialectic! That should be UPDATE `ctryvisits15`SET `Qtr`= 1 WHERE `WNo`< 14
  23. It's a lot like order of operations in math. If I want to add 2 and 3 and then multiple the result by 4, this will not work: 2 + 3 * 4 In math, multiplication and division are performed first. So the result of that would be 2 + 3 * 4 = 2 + 12 = 14 To get the intended result, you would have to enclose the addition in parenthesis (2 + 3) * 4 = 5 * 4 = 20
  24. Ah, The problem is the OR condition. Operators have a process in how they are interpreted. For AND/OR operators that are interpreted from left to right. For an OR operator, if the condition(s) to the left are True or if the condition(s) to the right are True - then the result is True. Your conditions are being interpreted as this If `idequipamento` IS NULL OR `idequipamento` =12 AND `idsala` =13 AND `idtempoInicio` <2 AND `idTempoFim` >2 AND `data` = "2015-06-12" The first record matches the condition because idequipamento is NULL. You need to use parenthesis to group conditions to be interpreted how you wish them to be interpreted SELECT COUNT( * ) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE (`idequipamento` IS NULL OR `idequipamento` =12) AND `idsala` = 13 AND `idtempoInicio` <2 AND `idTempoFim` >2 AND `data` = "2015-06-12"
  25. I think you misunderstand how a COUNT() query will work. I am assuming you are counting the number of records in the result set - which will always be 1. You will ALWAYS get a result - that result will contain the number of the COUNT() calculation. Using the example data and query you have above you should get a result with one record. That one record will contain a value of 0 - because there were no matching records. You need to extract the value from that result to get the number you are after.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.