-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Why? If I add up all the rows where staff_id=2 and the date is 01/2014 I get a total of 7780. Since your columns other than staff_id and amount are irrelevant, don't select them to keep your query simple. SELECT SUM(amount) AS total, sales_staff.`id` FROM sales_staff JOIN sales_league ON sales_staff.id = sales_league.staff_id WHERE YEAR(date_added) = YEAR(CURDATE()) AND MONTH(date_added) = MONTH(CURDATE()) GROUP by staff_id If you want to check what rows mysql is adding up, remove the SUM() and GROUP BY and run the query again: SELECT amount AS total, sales_staff.`id` FROM sales_staff JOIN sales_league ON sales_staff.id = sales_league.staff_id WHERE YEAR(date_added) = YEAR(CURDATE()) AND MONTH(date_added) = MONTH(CURDATE())
-
It's not daft, it's just the typical scenario. Typically your DB server is big and beefy where as your web-servers are smaller. Your DB server, if setup properly, should easily be able to handle requests from multiple different web servers. If you are at the point that a single DB server cannot handle it, then you need to determine what exactly the load is so you can address the problem. Most often the load is read-only stuff like SELECT statements. In those cases you setup one master which handles all write statements and then replicate to one or more slaves and the slaves handle all the read statements. If your app is write heavy then you'll need to explore ways of addressing that. This is not an area I am familiar with so I can't say anything to specific about it. It's a situation that is not typical and few have to deal with.
-
The point of the comment was that you should be using jQuery as it will simplify your ajax interactions greatly. For instance it has a simply .load method you can use to request a URL and drop it's contents into a div. You then just create timers for each of your divs that you want to refresh and call the .load function whenever the timer ticks. Note that browsers will limit you to two concurrent requests typically. If you have a bunch of divs trying to refresh at the same time, you'll be better off scripting things so that you get all the data for each div in a single request. Otherwise some will be delayed until the others are finished.
-
Lookup and Find a table and show data based on another table
kicken replied to ArthurHick's topic in PHP Coding Help
Yes, first you SELECT the controller id from your controllers table and read the results into PHP. Then you take that ID and generate a new SELECT statement for the appropriate table name and run that query. -
Your code suggests the field is being posted, just with an empty value. There is nothing wrong with your HTML however so I suspect one of two things 1) You have some PHP code you did not show which is causing the value to be cleared out or 2) You have some JS code you did not show which is causing the value to be cleared out. Check your browser's developer tools to see what value is being sent in the request to the server. You can find this out from the Net/Network tab usually. Note for future posts, you need to wrap your code in tags when posting. It makes it much easier to read that way.
-
I think he's already using a list, but has the li's set to display-inline so they show on a single line rather than a vertical list. The new lines in the source are causing undesired spaces though. One way to fix that is just change where your new lines are so they appear within a tag. Eg: <ul> <li>A</li ><li>B</li ><li>C</li ></ul>
-
The query string variable does not contain the ?, so leave that out. Also it's \d, not /d. RewriteCond %{QUERY_STRING} id=(\d+) RewriteRule included/bee\.php$ bee.php?id=%1 [R=301,L]
-
Nobody said anything about tables. You either generate even/odd class names and apply them like any other class, or you use the :nth-child selector.
-
log
-
Your code could be improved quite a bit. For instance there is no need to execute the tail command, and you can streamline your processing into less code. <?php //First we read in all lines $lines = file('counter.txt', FILE_IGNORE_NEW_LINES); //Then get the last line from the array of lines $last = $lines[count($lines)-1]; //Split the line into the interesting parts. list($day, ,$hits) = explode(' ', $last); //If the day matches today, increase hits and overwrite, otherwise add a new entry $today = date("D-m/d/Y"); if ($day == $today){ $hits++; $lines[count($lines)-1] = "{$day} hits {$hits}"; } else { $lines[] = "{$today} hits 1"; } //Re-write the file file_put_contents('counter.txt', implode(PHP_EOL, $lines)); You'll need to add your own validations/error handling such as what to do if the file doesn't exist or is empty. As for your large count, have you checked your server's access log? You might just be getting hit by a bot or two that day causing a large number of hits.
-
Use the DISTINCT keyword in your query. SELECT DISTINCT DeptName FROM tbldepartmentlist
-
As mentioned, you should be storing your team IDs, not their names, in the matches table. So rather than you would have ID - 1 Home - 1 Away - 2 ID - 2 Home - 3 Away - 4 Then you would need two inner joins, one for the away team and one for the home team. Both joins would link back to the teams table, but with a different condition. SELECT matches.ID as matchId , home.Team as homeTeamName , home.Tag as homeTeamTag , away.Team as awayTeamName , away.Tag as awayTeamTag FROM matches INNER JOIN teams as home ON home.ID=matches.Home INNER JOIN teams as away ON away.ID=matches.Away The first INNER JOIN connects with the teams table finding the row which matches the Home ID. This is aliased to home so we can reference it within the select list. The second INNER JOIN is the same as the first, except it matches the Away ID and is aliased to away.
-
Depending on what you actually need to do when the time expires, you may not even need to schedule anything. Essentially what you'd do is when the user clicks the upgrade button, you would record one of two things (or both) 1) The time they clicked the button or 2) The time the upgrade would be complete. Eg: INSERT INTO user_building (BuildingId, CompletedAt) VALUES (?, NOW() + INTERVAL 5 MINUTE) In your code to display buildings to the user you can check the CompletedAt value and if it is < the current date, calculate the time remaining before it is completed. If the display to the user is all you need to change when the building is complete then you don't need a cron job or timed task at all. If you do need to do some other tasks then you could have a cron join run every minute to search for newly completed buildings and do whatever is necessary. The timing wouldn't be perfect but would be close. If you want to get even better timing what I would do is setup a daemon process you can communicate with and initiate some kind of timer within it. Sort of like your own customized cron daemon.
-
The AS is optional. I tend to leave it out when I alias tables, but include it when aliasing a column. No particular reason why, just preference/style. The table prefix is only required if the same field name is used in multiple tables used in the query. If the field names are unique you can leave the table prefix off if you want. Including it however makes it clear exactly which table/field you are selecting. It's all about readability.
-
The first place you look should be in the Accept-language header (available via $_SERVER['HTTP_ACCEPT_LANGUAGE']) the browser sends. That will tell you which languages the user wants and in what preference order. For example my browser sends: Accept-language: en-US,en;q=0.8,de;q=0.6Which means my ideal language is en-US (American English), my second-choice would be en (Generic English), and lastly de (German). If by chance the client does not send such a header, then you can either fall-back to some kind of IP detection (just google for services) or pick a default language. As for changing the language if the user decides they want something else, the simplest thing is to just reload the page. Any other method would get fairly involved with JS and having to replace text nodes on the page. Just have a link the user clicks which reloads the current page and sets their language preference somewhere (session/cookie).
-
Your issue is that when you hover over the h2/p elements, you are no longer hovering over the image div.preview element so it triggers the mouse-out portion. Once that hides the overlay though then you are once again hovering over the image so it triggers the mouse-over portion and shows the overlay again. This is what is causing it to flicker. The simplest fix would be to just target the parent li tag, as suggested by trq, for the hover event as regardless of whether you are hovering over the overlay or the image you are still hovering over the li element. Now, on an unrelated matter: When replying please do not quote entire posts. Only quote whatever is relevant to your response, or nothing at all. We all have scroll bars, we can go back if necessary.
-
This part of your create table: ON DELETE NO ACTION ON UPDATE NO ACTION specifies what happens when you try and delete or update the key in the associated table. Possible values are: NO ACTION / RESTRICT: Prevent the delete/update from occuring SET NULL: Set the value to NULL CASCADE: Perform the same operation on this row (ie, either update it to the new value, or delete the row) SET DEFAULT: Set the value to the defined default value So, what you want to do is specify ON DELETE CASCADE ON UPDATE CASCADE
-
How to create a real-time JavaScript,php and mysql progress bar?
kicken replied to kg's topic in PHP Coding Help
A few things to note: a) In order to track the progress you have to be able to track how many rows have been inserted out of the total amount of rows. With a simple INSERT INTO...SELECT that is not possible. You would have to select the data out into PHP and then generate single inserts to process. While this would allow tracking, it would also slow down the process considerably. b) You need somewhere to store your progress information, such as the session of a memory cache. If you use the session you need to take care to avoid keeping the session locked. Your script doing the inserts would write it's progress to this location, and you'd have another script read that location to determine the values. c) Since the only effective way to do a progress bar is to have a periodic ajax request check on the progress, it's not really practical to implement a real progress bar for something that would likely take no more than a few seconds. If all you're doing is inserting 28 rows then you most likely fit into this description. It'd be easier and just as informative to use a fake progress bar or just skip it all together. Now, in the event that you did actually have something worth a progress bar, you can take two approaches to it. One would be to estimate the rate of progress and just sort of fake it based on that, the other way would be to constantly check on the progress. For exceptionally long tasks you could combine these two methods.- 2 replies
-
- php
- javascript
-
(and 1 more)
Tagged with:
-
CSS3 provides a pseudo-selector for this called :nth-child. If you want something that works on much older browsers then you'll need to have your PHP code generate alternating class names, the most common method of which is using the modulus operator. eg: $class = $rowNum%2?'odd':'even'; While you could apply the effect after the affect with jQuery (as you tried) it is unnecessary to involve Javascript in something such as this.
-
Your sort order should be another field, not based on the ID field. Then you can adjust the order of your records however you want without having to mess around with the IDs. Add a column named SortOrder to your table, make it an INT column and number the records in the order you want them to appear. Alter your SELECT for those records to add ORDER BY SortOrder so it will properly order them.
-
No, you could write it in Javascript. You'd only need to implement it in PHP if you wanted to keep people from viewing your implementation details. In this particular problem there is nothing that PHP can do which Javascript cannot.
- 3 replies
-
- bin packing
- graphical
-
(and 3 more)
Tagged with:
-
Your image doesn't show jack-shit. You were asked what your table definition was, not what values it contains. You can get the definition by running a 'DESC tableNameHere' query, or just post the CREATE TABLE statement you used when creating the table. Secondly, assuming there is no problem with the table definition, there is no reason those columns would contain 1 rather than the values you set. There is nothing syntactically wrong with your query or code. As such, the most likely explanations are: 1) You are not giving us an accurate representation of your code or 2) You are not verifying the results of your code accurately. There have been numerous times people have come on here adamant that they have correctly checked things only to realize days later(after being told numerous times) that they actually were not. Hence the suggestions to make sure you are checking correctly by having your code select and output the data after inserting. Or at the very least have your code output the ID for the row just entered and make sure you match it up properly when check the table data.
-
Based on what you wrote for requirements, the entire thing could be done with just Javascript without any need for PHP at all. If you want to use PHP that is fine, but it is unnecessary unless you want to do some kind of DB interaction like save/load stuff. For the UI you would just design your web page however you want things to display, then add the interactive stuff like drag-n-drop using Javascript. jQuery will make the javascript part considerably easier to implement and help keep things organized better.
- 3 replies
-
- bin packing
- graphical
-
(and 3 more)
Tagged with:
-
Store the comments in your database. Either in a TEXT field or large VARCHAR field. Other profile information you would store in the database also, in fields of the appropriate type.