Jump to content

xtopolis

Members
  • Posts

    1,422
  • Joined

Everything posted by xtopolis

  1. Granted, I don't have a lot of experience with this myself, but I'm not sure you entirely understood ALL the methods they were talking about in that thread. Play around with it and see if you find something that works/is efficient/manageable.
  2. It would be easy to implement sessions afaik.
  3. Thanks, while that version produced this error: I was able to fix it by using removing the alias for the main table: SELECT aion_accounts.class_id, COUNT(aion_accounts.class_id) as class_id, ( SELECT COUNT(timezone) FROM aion_accounts tz0 WHERE tz0.timezone = 0 AND tz0.class_id = aion_accounts.class_id ) AS US, ( SELECT COUNT(timezone) FROM aion_accounts tz1 WHERE tz1.timezone = 1 AND tz1.class_id = aion_accounts.class_id ) AS EU FROM aion_accounts GROUP BY aion_accounts.class_id If possible, could you explain the above error? I tried googling on "SHOW KEYS FROM", but didn't see any solutions/explanations. Also, using these ?subqueries?, is this an efficient way of doing this? Would it be better to join another table instead on a FK of aion_accounts? I define better as which would be less taxing on the query itself.
  4. Hi, One of my tables looks like this: [pre]account_id toon_name user_id class_id craft_id timezone ------- ----------------------------------------------------------- 1 Steve 1 6 6 0 3 Barry 3 2 3 1 11 Fred 11 5 2 0 15 Lisa 15 1 3 1 20 Joe 20 6 5 1 32 Frank 32 1 0 0[/pre] This query returns: SELECT aa.class_id, COUNT(aa.class_id) FROM aion_accounts aa GROUP BY aa.class_id ORDER BY aa.class_id ASC correctly returns this result: class_id COUNT( aa . class_id ) 0 1 1 8 2 5 3 9 4 4 5 3 6 9 7 3 8 6 Question I recently added the timezone column which is a tinyint that will hold values: NULL, 0, or 1 (perhaps more, but not likely). Is there a way get a result set which has the query above + two additional columns: a count for timezone set to 0, and timezone set to 1 ? So it would be like this (based on that table): class_id COUNT( aa . class_id ) COUNT(timezone=0) COUNT(timezone=1) 0 1 0 0 1 8 1 0 2 5 0 0 3 9 0 1 4 4 0 0 5 3 1 0 6 9 1 1 7 3 0 0 8 6 0 0 How would I write this query? I have a feeling is has to do with a sub query or self join, but I am not well practiced in those areas. Any tips would be appreciated. (Also, if you think my table should be normalized differently (put timezone elsewhere), I am open to suggestions. . . . . Source: CREATE TABLE `aion_accounts` ( `account_id` int(5) NOT NULL auto_increment, `toon_name` varchar(255) collate latin1_german2_ci NOT NULL, `user_id` int(5) NOT NULL, `class_id` tinyint(1) NOT NULL, `craft_id` tinyint(1) NOT NULL, `timezone` tinyint(1) default NULL, PRIMARY KEY (`account_id`) ) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=50 ; INSERT INTO `aion_accounts` VALUES (1, 'Steve', 1, 6, 6, 0); INSERT INTO `aion_accounts` VALUES (3, 'Barry', 3, 2, 3, 1); INSERT INTO `aion_accounts` VALUES (11, 'Fred', 11, 5, 2, 0); INSERT INTO `aion_accounts` VALUES (15, 'Lisa', 15, 1, 3, 1); INSERT INTO `aion_accounts` VALUES (20, 'Joe', 20, 6, 5, 1); INSERT INTO `aion_accounts` VALUES (32, 'Frank', 32, 1, 0, 0);
  5. As far as I can see, you are trying to gather POST values that don't exist anymore... after the header() redirect, I wouldn't expect them to still exist at all. You could double check by doing a print_r($_POST) on the page you're redirecting to. In the case where I want sticky forms, I usually use sessions to store the data.
  6. Additionally, why not use InnoDB if you want support for the FK constraints? Comparing Access to MySQL isn't exactly correct afaik. Access is a GUI built on top of a storage engine, MySQL is a storage engine... PHPMyAdmin might be a better comparison for Access, but not MySQL I think.
  7. We're all learning here... and getting newbies to post in the right place sounds hard enough as is. I would just suggest asking questions in a manner that gets you more answers than snide remarks. Or explain that you're new and want people to be easy on you in your threads... besides, CV likes it rough.
  8. Regarding adding the column of "groupid" to the employee table: -This is only acceptable if they will only ever have one group, or you represent multiple groups by another manner, such as binary. I personally am not good at binary, so I prefer to have a lookup table so I can easily manage a user belonging to any number of groups. I also do it this way so as to plan for growth/changes in the application. Perhaps your needs show that all employees must belong to the employee group for mailing out announcements... but new hires must belong to the new hire group as well for management reason. -You don't know that this situation will ever happen, but the more normalized your tables are, the less trouble you would have implementing these new requirements should they come along. -What you want to stay away from is using a single column to store multiple values like (1,3,22) as a comma-separated-string.. that's bad news right there. Note: You may want to break your name column in the employee table into firstname and lastname columns. This can aid in selection, presentation, etc... NOTE2: I made a mistake naming the timetable column "when". It is a reserved word, and should not be used as a column name. Sorry. Regarding your query for getting the employees with a certain status (on break, etc): -I will look into this more later, or someone else could comment with a sample one. I was trying to do a small example but got busy.. I'm not sure whether my proposed design will work or not, but it's worth testing. Also, there are already made solutions out there that you could review and model your own after.
  9. Hey, Trying to answer the questions that I saw: 1)Making this work as a foreach (loop) -Without knowing a little bit more about your tables, I can't give an example. It's pretty easy though, just select the data correctly in MySQL so that it comes out per row, and loop through it, just like any normal loop. Without having your structure and some sample data, it's hard to guess at how your tables might JOIN together. 2)Deleting records -First, unless it's sensitive data, we don't really "delete" records. Common practice is to mark them as "deleted" and not show them, but to not actually delete them from the database. I was a little confused about the deleting things in two places, but there are database types which enforce things like this (InnoDB) and you should manage it with a script that does it for you, so you don't have to remember anything.
  10. Hi, First off, the examples I supplied were to get you thinking about the big picture of your application, as well as to show you some better database normalization. There is no "right way", only the way that works for you and meets your needs. It should become clear what your needs are, and how things can be broken down after you've drawn it out on a piece of paper. The method I suggested for tracking (Different event types) may or may not be suited to your needs. I have not created a timeclock type system before, so I was only speculating about how it might be used. I've briefly glanced at your code. It is my suggestion that you would start off on validating the employee id first (since everything relies on being linked to the employee) and then take them to a second page with options of what they can do. (ie:, if their last event was a SHIFT START, they would have: START LUNCH, END SHIFT available to them, but not END LUNCH or START SHIFT). Regarding it not inserting into the database, this might be because you have 4 arguments in the prepare statement, and 2 in the bind_param statement. I am not sure since they are null whether or not they need to be represented. It also appears that your schema for Timetable isn't being match in the statement. You give it NULL, NULL, int, int, when they fields are int(auto), datetime, int, int. At the very least it should be datetime(like: date("Y-m-d H:i:s")), int, int Also, if you are not seeing error messages, first try adding: error_reporting(E_ALL); ini_set('display_errors', 1); to the top of the page (below <?php of course) and it will show ALL errors. If you still see no errors, trying copying the query into MySQL directly (or via PHPMyAdmin) to see if it complains. Hope that helps.
  11. I think you are making this more complicated than necessary. My basic approach would be to start with a database design like this: [pre][employees] empid(int,auto) | firstname(varchar) | lastname(varchar) ----------------------------------- 1 | bob | finlid 2 | steve | perry 3 | sam | daman [employee_groups] empid(int) | groupid(int) ------------------ 1 | 1 2 | 2 3 | 2 [groups] groupid(int,auto) | groupname(varchar) -------------------- 1 | Manager 2 | Employee [timetable] timeid(int,auto) | empid(int) | when(datetime) | eventtype(int) ---------------------------------------------- .. 46 | 1 | 2009-07-14 08:30:39 | 0 47 | 2 | 2009-07-14 08:34:21 | 0 .. 57 | 2 | 2009-07-14 16:01:20 | 1 [/pre] Break the tables down into their parts and only record what's relevant. You don't want to use any on update current timestamp in my opinion. I can't think of the query off the top of my head, but if you have the start time, end time, and also in between times (lunch breaks?) you could find out how many hours were worked, etc. If you notice in the last table design, I use the eventtype column. This could have its own relational table holding those types I mentioned: start, end, lunch(start), lunch(end) etc. You can also add more easily. The same goes for the user type. I have groups that users can be a part of managers, employees... and then you can allow those GROUPS to edit or not edit, etc. I strongly suggest you draw out this on paper first, thinking clearly about what functionality it needs to have, and what formulas it will use to calculate which values. Lay it all out on paper so you can get an idea of how it might fit together. Don't forget to account for human errors: (not clocking out), (daylight savings time if available), holidays, etc...
  12. Match the argument count then, blank or not, you're still passing an array of 4 values to a statement with 3 place holders. Otherwise, if it's auto-inc, then likely you could leave off the first argument in the data array so it would just be $data = array(3, 'Cameron', 'Kirk'); Match the argument count. edit: RTFM
  13. The table from your second image needs to be broken up into smaller tables with relational data. (you can read this article: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html) For your specific problem, you would add another table, and not have the "cat" column in your ... whatever that long image is. The new table would have the relationship of (one) image -< to -< (many) categories So the lookup table you would make would at basic form be this: [pre]image_id | category_id ---------------------------- 107 | 2 107 | 4 108 | 2 109 | 1[/pre] If that isn't clear enough, read the article I posted, and then if you still have questions, post back here. I strongly suggest reading the article first, then modifying your image table which has too many columns on it that are not related.
  14. Read this article: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html It deals with some similar data of yours (storing addresses) and should be useful.
  15. Can't he just apply the background-position declaration and align it? If I remember correctly, if it's too big the excess won't be shown. The downside would be that it loads the huge image regardless of screensize.
  16. Are you saying so that it only changes it to valid titles? <?php $validTitles = array("tos", "feedback", "home"); if(in_array($_GET['action'], $validTitles)) { $title = $_GET['action']; }else{ $title = "yoursitename.com"; }
  17. Well, is there a file called header.php? I am not 100% on this, but does that file also have the appropriate <?php ?> tags in it? Any errors from your tests rather than "it doesn't work" ? And skunk wasn't insinuating that that I know. It is for your own safety. Remotely accessing content you have no control over is a bad idea. What if it changes without your knowledge?
  18. Your second argument for move_uploaded_file() looks weird. Try if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], $file_dir . "/" . $file_array['name']) or die ("Couldn't copy"); print "file was moved!<br><br>"; } Though that may not change anything
  19. for the bottom part it would be something like this: <?php $category = (isset($_GET['cat'])) ? intval($_GET['cat']) : 1; //if a category is set, use it, if not, default to 1 $sql = "SELECT imageReference FROM yourTable WHERE cat_id = $category"; //do mysql query stuff and display the images ?> You would of course add more checking that the category integer is valid, and change the query to match your database.
  20. Where is the header/footer located? Is it on the same webserver, and in the same folder as index.php? Or is it on another website? You can read here about the limitations and warnings for include: http://us3.php.net/manual/en/function.include.php To directly answer your question, it is not limited to .html/shtml in the least. The likely issue is either a) you are trying to remotely include [like skunk suggested] or b) have the wrong reference to location
  21. You could concatenate the categories onto the url with a delimiter, and then explode them for the query and use IN() for the selection. Example, say these are checkboxes (name(value)) [] food(1) [] hiking(2) [] surfing(3) You would then get the values of all selected checkboxes, and concatenate them together. So if I selected food and surfing, and a delimiter of '|' I would have a string like: 1|3 which I could append to the url such as: yourpage.php?cat=1|3 (a better idea might be to do it with binary values so that you just send a single number) Anyway, on your page with the sql, you would explode on |, and make the query: SELECT * FROM cms_articles WHERE id IN (1,3)
  22. From the code you have supplied, all I can see is the two buttons that you have after clicking the first image. You don't have any code about "doing something else when the second image is clicked". (ie, function showBookie() isn't included in your code) You need to ask a specific question, and supply relevant code. You didn't really ask a question, and the code you have doesn't handle the problem you said you have.
×
×
  • 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.