Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. name is just the string "screen". If you want to get the value of window.screen you can also do that with window["screen"]...
  2. What do you have so far? Why are you using a CSV and not a database? What is the purpose of this +10%?
  3. Then make your code change the values. Is that the part you don't know how to do?
  4. Use Javascript to trigger a refresh. window.setTimeout(function() { document.location.reload(); }, 60000);
  5. It's not outright stated so I want to confirm it: subcategories can themselves have subcategories, right?
  6. Disclaimer: lots of stuff about MVC is debatable. The below is my opinion on how it should all work. Determine the reason for the change. Line Y must be something significant for it to be deliberately removed from the page. What is it? Why is it being removed and not X or Z? Then you need to consider what roles and responsibilities are given to the model, controller, and view. Since you (now) know the reason for the change you can decide which of those three should be in charge of any relevant decisions. - The model is in charge of the properties and behaviors inherent to the thing (ie, product) itself. For example, products inherently have a name so that should be handled in the model. - The controller is in charge of ferrying data and operations between the view (what the user interacts with) and the model (where the data is stored). If someone wanted to change a product's name then you would do the "if they're changing the name then make the product's name change" logic in the controller, keeping in mind that the name itself should still be handled by the model. (That is the result would be the controller telling the product model to change its name to some new value, or simpler that the name has changed to a new value and the model should commit the change.) - The view is in charge of outputting data and making sure the controller can get inputted data as well (ie, setting up s and the like). It knows about the HTML, it knows about the structure of the page, and it knows about how the data should be placed on the page. Without actually knowing your system I'm going to assume that the three line things were supposed to be tidbits of information that applied to all products, except now they apply to all but those three you're dealing with. Information itself belongs in the model because that is what is responsible for products' properties, and the line things are properties of the product. All (almost all) products, perhaps, but still of the products themselves. So instead you should be accessing them, and hopefully storing them too, with the model. Next the controller gets the product model and, surely among other things, grabs the line things from the model so that they can be sent to and displayed in the view. All it sends is the three "Line X", "Line Y" (if desired), and "Line Z" bits - no HTML markup. The controller doesn't even care what the actual line items are because what they are has no bearing on how the controller operates. When the view takes over it receives those three (or two) line things and decides to output them as HTML using s to separate each. Again, the view doesn't care what the line items are because what they are doesn't matter for how the view displays them. Product model class Products extends Model { public function getLineThings() { /* exactly what you do here depends where these line things come from. while they really shouldn't be, I'm just going to hardcode them here. */ // the particular products #2, #3, and #5 have X and Z if ($this->id == 2 || $this->id == 3 || $this->id == 5) { return array("Line X", "Line Z"); } // otherwise all other products have X, Y, and Z else { return array("Line X", "Line Y", "Line Z"); } } }Page controller class WhateverPageThisIsController extends Controller { public function execute() { /* (pretending this is where the controller executes itself) */ $product = Products::getParticularProduct($some_inputted_value_or_something); $view = $this->getViewDataBag(); $view->linethings = $product->getLineThings(); /* and now the relevant view gets executed using the data I just put in $view */ } }View <?php $data = $this->getViewDataBag(); // the $view from the controller // ... // now output the line things $linethings = $data->linethings; // the data is just an array - it needs to be turned into HTML $html .= implode("<br>", $linethings); // Line X<br>Line Y<br>Line Z // ...
  7. How about posting the rest of your code? And the HTML form too. Speaking of the form, does it have an enctype="multipart/form-data"? Take a look here if you haven't see that yet.
  8. What "group files" are you talking about? Require group X?
  9. Bear in mind that the code is deliberately trying to confuse you. And doing it well - I'm having a hard time following it all in my head. It's a bitch to explain too. Disclaimer: this is the short explanation that tries to address how other languages (except PHP, ironically enough) manage scope too. Java has a hierarchy of scopes - places that variables can be found. At the top is class scope, below that is method scope, and below that there can be a number of block-level scopes, each of which could have more block-level scopes inside. - Block-level scope, such as inside an if or loop. The variable is destroyed when you leave that scope. if (z < 50) { int x = 90; // defines x but only within this if block- Method scope, such as in the method signature. int m1(int y, int z) { // defines y and zVariables can also be defined inside a method (and outside any loops or such). void m2() { int z = 40; // defines z but only within this method- Class scope, which is where FindInteger has definitions for x, y, and z. public class FindInteger { int x = 10; int y = 20; int z = 30;When you refer to a variable "x", Java looks for the variable starting at the current scope and works its way "up" the hierarchy: first in the current block (if any), then up each block (if any), then finally to the method and then to the class. Here is a fun diagram of where the variables are defined. FindInteger public class FindInteger { +------------+ | | int x = 10; | x | int y = 20; | y | int z = 30; | z | | | | m1 | | +--------+ | int m1 (int y, int z) { | | y, z | | int x = 15; | | x | | y = x + z; | | | | this.y = y + 10; | | | | IO.outputln(...); | | | | return y; | | | | } | +--------+ | | | | m2 | | +--------+ | void m2() { | | | | int z = 40; | | z | | int y = m1(x, x); | | y | | | | | | | | if | | if (z < 50) { | | +----+ | | int x = 90; | | | x | | | z = x + y; | | | | | | } | | +----+ | | | | | | x = x + y + z; | | | | IO.outputln(...); | | | | } | +--------+ | | | | main | | +--------+ | void main(String[] args) { | | args | | FindInteger q = ...; | | q | | q.m2(); | | | | IO.outputln(...); | | | | } | +--------+ | } +------------+ When you're looking for a variable, you start inside whatever block you're in at the time and work your way outwards until you find it. Here's a crazy explanation of the execution: FindInteger q = new FindInteger; // q.x=10 q.y=20 q.z=30 q.m2(); +--entering m2 scope-- // x->this.x=10 y->this.y=20 z->this.z=30 | void m2() { // x->this.x=10 y->this.y=20 z->this.z=30 | int z = 40; // x->this.x=10 y->this.y=20 z=40 | int y = m1(x, x); // x->this.x=10 y=? z=40 | | +--entering m1 scope-- // x->this.x=10 y->this.y=20 z->this.z=30 | | int m1(int y, int z) { // x->this.x=10 y=10 z=10 | | int x = 15; // x=15 y=10 z=10 | | y = x + z; // x=15 y=(15+10)=25 z=10 | | this.y = y + 10; // x=15 y=25 z=10 this.y=25+10=35* | | IO.outputln(...); // "x: 15 y: 25 z: 10" | | return y; // x=15 y=25 z=10 | | } | +--leaving m1 scope-- // x->this.x=10 y=25 z=40 | | if (z < 50) { // x->this.x=10 y=25 z=40 | | +--entering if scope-- // x->this.x=10 y->m2's y=25 z->m2's z=40 | | int x = 90; // x=90 y->m2's y=25 z->m2's z=40 | | z = x + y; // x=90 y->m2's y=25 z->m2's z=(90+25)=115* | | } | +--leaving if scope-- // x->this.x=10 y=25 z=115 | | x = x + y + z; // x->this.x=(10+25+115)=150* y=25 z=115 | IO.outputln(...); // "x: 150 y: 25 z: 115" | } +--leaving m2 scope-- // q.x=150 q.y=35 q.z=30 IO.outputln(...); // "x: 150 y: 35 z: 30" *s are where variables from outer scopes get modified, and where you're losing track of values. I suggest you try a smaller bit of code with fewer variables to keep track of. Play around with methods and class variables and ifs and loops and variable declarations and stuff, see what happens. That's the best part about programming: if you're not sure how something will go, try it and find out.
  10. Java and Javascript are two completely different things. Yes, there are class variables named x, y, and z, but the method you have defines it's own versions. It's called variable shadowing.
  11. COUNT() will count non-null values. Not distinct values. Either you want a condition WHERE items_listed = 1 or you want a SUM() of the values, it depends how those values are managed.
  12. Use mysqli_error to find out what happened.
  13. Right. That value for $date is supposed to be a number like the one you get from strtotime() or mktime() - a number is much easier to work with than some kind of year-month-day string.
  14. There has to be something somewhere that is aware of the configuration of the parts. If it didn't then the application wouldn't even know of the fact that the parts are combined. That's where the logic goes.
  15. .htaccess-based authentication will work as well as any username/password combination - meaning you need strong passwords - but without you having to implement (and potentially expose bugs in) the system yourself. The downside is that it's not very user-friendly because all they get is a popup prompt in their browser. Unless you changed the log format, the access logs will tell you who hit what URLs. To make your code aware of the username, look to $_SERVER["PHP_AUTH_USER"].
  16. So you don't want a new page for each link, rather clicking the link scrolls you down the page to that letter? First a thought. What do you do if there's no content for a letter? Disable the letter's link? Show the letter heading with nothing under it? For the scrolling you do want anchors - the link you have now goes to a separate page. = $i ?>Your H3s are already set up to work with anchors because you gave them IDs. Oh, and notice how there's no style in there? Use actual CSS rules somewhere, not inline styling: it'll save you not just bandwidth but time later when making changes to it. As for the code you want to add, it's not quite right. See that it uses $firstletter everywhere? That won't help you do anything. Set $currentletter = "" before the while loop. That's what you'll be comparing each letter against. Inside the loop you can grab the $firstletter (though you have to look at $company['t1'] instead of $row['name']). By the way, fix those column names if you still can: "t1" and "t2" are meaningless. Then insert the rest of the code (substituting in $currentletter where appropriate) before the output you already have in place, remembering to add the } that's missing from what you posted. If you're having problems after that, please post the full code you have and explain what problem you're having.
  17. How do you handle 404 pages?
  18. Actually, that's the way I would do it too. [edit] For the record, a "session" tends to mean a user's $_SESSION and the underlying technology to support it. "Two sessions" is a bit weird but could mean either two users and their two separate sets of $_SESSION values, which is what I thought at first, or one user somehow with two sessions (like maybe you destroyed the first session and started a second one). "Three sessions" is even weirder.
  19. Please, no. That mentality causes so many problems with software and I, for one, find it incredibly frustrating when people use it. That's actually what I thought, but you kept talking about the week number. So you've got a date and you want to know the previous Sunday and the next Saturday? The very first bit of code you posted was correct-ish - just had to make time() a variable. $date = strtotime("2014-01-01"); // for example // break out the parts of the date list($y, $m, $d, $w) = explode("-", date("Y-m-d-w", $date)); // sunday is w days ago $sunday = mktime(0, 0, 0, $m, $d - $w, $y); // saturday is (6 - w) days in the future $saturday = mktime(0, 0, 0, $m, $d + 6 - $w, $y);Adding seconds, like you had with 24*3600, is imprecise because not all days have 86400 seconds. Plus daylight savings can give you unexpected results.
  20. }elseif($guess = $number) {One equals sign is for assignment, two equals signs are for comparison.
  21. It depends on how you define weeks - particularly around the boundaries. Consider December 31st, 2013 (a Tuesday) and January 1st, 2014 (a Wednesday). What week numbers do they get? a) 2013-W52 and 2013-W52 because the week started in 2013? January's is a bit odd. b) 2013-W52 and 2014-W01 because of their respective years? Neither week has seven days: three for 2013-W52 and four for 2014-W01. c) 2014-W01 and 2014-W01 because the week range contained January 1st? December's is a bit odd. (This is how 'W' works.)
  22. Uh... Just to be absolutely clear here: when you say you have three "sessions", are you saying that you have three visitors to your site and you want to be able to access all three's session data at the same time? Or that you have three things of data in the session and you want a maximum value of them? Or perhaps simpler, what's your code so far?
  23. Your problem was that you didn't know how to get the data from the other sessions. My solution is to not use sessions because if you put it all in a database then you can get the other data. But hey, solved or not solved makes no difference to me.
  24. Why the heck are you naming your variables and inputs with underscores?
  25. And? The fact that people don't log in is irrelevant.
×
×
  • 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.