-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
You can set both at once like: $time[] = array( 'hour' => $hour, 'minute' => $minute ); But it kind of depends where you're getting the data from. Using a loop like you are doing is good for the hour, but you then need the minutes. Are you just wanting to generate an array for each hour with 0, 15, 30 and 45 minutes?
-
In this line: $time['hour'] = $hour; You're overwriting the "hour" index in the array on every iteration. I'm guessing you either just want: $time[] = $hour; To have a single dimension array holding the times, or: $time['hour'][] = $hour; If you want the hour index to be an array itself.
-
CAPTCHA....Ya killin' me smalls!
Adam replied to austinlikesdubstep's topic in PHPFreaks.com Website Feedback
http://www.cracked.com/blog/5-things-spammers-ruined-while-we-werent-paying-attention/ -
No, you would them a unique key. You can only have one primary key.
-
Put together this little example, which is the same concept as yours but works exactly as it should. The problem is with your implementation, but you're only providing abstract pieces of it so it's hard to build up a decent picture of what's happening.
-
Your incrStr(), incrDef() and incrHealth() methods shouldn't return a string dictating what happened. There's actually nothing happening in the methods that could go wrong, so you know at the point of invoking the method that it will be successful, and of course you have the value passed in available. It would be better to return $this so that you can chain the calls: $player->incrHealth(30)->incStr(-40); Similarly, the getStats() method shouldn't return the data concatenated into a string and the constructor shouldn't be echoing anything. The problem with returning strings that you output, is that you're mixing your application logic, or more specifically your model, with your view logic. This can introduce a whole range of problems when you later make changes. The object representing a player shouldn't determine what output is shown to the user -- just have it return the data, so the view can decide. You may think that would make it less reusable, but you can always reuse the view. The MVC pattern is a really good example of how to split such concerns, and is what the majority of decent PHP frameworks out there have adopted.
-
To or not to display Messages on updates, confirmation, etc...
Adam replied to rudyten's topic in Application Design
There are no standards on how to display errors, it's really just a design consideration. It's best to keep it consistent across the site though, and easily noticeable from the start. The other day I had to contact the council tax office, so sent them an email through their site, and was about to close the tab before I noticed a small one line error hidden amongst a bunch of other text kind of implying the message had been sent, saying "Your session has expired". I don't know if the email was sent or what? Completely ruined my experience of their site, simply because they didn't highlight the error message or give any clear explanation of what had happened. The messages themselves, in my opinion, should be lightly detailed so the user understands what didn't work, but don't contain any confusing terminology or expose the server side implementation (like a MySQL error). Just keep it simple and short, but informative. -
You need to provide much more context of the code for us to help you. My guess would be that you're not using it with a post defined in the current scope, as I believe WordPress just use the horrific global keyword to get the data into the function.
-
You can't mix JavaScript and PHP like that (even if it was syntactically correct). PHP is processed on the server and the resulting mark-up (including the JS) is handed to the browser to parse. The JavaScript should be something like: <script type="text/javascript"> var conf = confirm('Do you want to add new stuff?') if (conf) { window.location = '...'; } </script> Although where are you putting this code?
-
I agree. If you encounter a variable named $answer you're likely to assume it contains a single answer, where as $answers obviously implies there's multiple. Plus say in a foreach loop it means you can keep the naming semantic: foreach ($answers as $answer) { .. Without having to create odd or meaningless names like: foreach ($answer as $answerItem) { foreach ($answer as $item) {
-
Where is newName defined?
-
What are the values of string and string2? My guess would be that your sorting logic is a little off - how are you doing it?
-
You're not declaring it a string like you think, it's a number. What you're seeing (4.54544878545455e+17) is scientific E notation. JavaScript does this so it can represent numbers larger than it's internally physically capable of storing. Your number exceeds that maximum, so you're loosing some bits off the end and it's being rounded. You can see the cut off point here: var num1 = 9007199254740992; var num2 = 9007199254740993; if (num1 == num2) { // true } If you only want a string, just define it wrapped in quotes and you won't have a problem. If you don't, things get more complicated, but I'll wait and find out before spending the time typing it up!
-
At what stage is the redirect happening? XHR requests should just follow them as usual and return the result of the end request.
-
If I understand you right, you just need to assign the same function to multiple events. I'm not sure in that case why you would need to determine which event was fired though? If different events achieve the same outcome but do things slightly different, you should define an additional function(s) to handle chunks of the process that your event handlers can use, to avoid repetition. The code you provided is almost right for assigning a function to an event, except there's a subtle problem. document.onmousedown = eventHandler(); By including the parentheses () on the end, you're invoking the function immediately and assigning the result to the event. You should just pass the function name: document.onmousedown = eventHandler;
-
The jQuery toggle event makes it really simple: $('li').toggle(function() { $(this).addClass('selected'); }, function() { $(this).removeClass('selected'); }); You'll want to change the selector ('li') to match your specific element though.
-
Your selectors refer to the DIV by "#result", instead of "#results".
-
Opening in the same browser window is the default behaviour for a form. Are you meaning tabs?
-
No you should be checking they're logged in for every page (generally), I'm saying don't have the header HTML within a file you've called "check_login.php". Doesn't make sense. Instead put the header HTML it in it's own file (header.php or something) and include that once you have verified their login and performed all your database queries and stuff (your application logic).
-
This constitutes as "HTML, text or even white-space": <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/modified-style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <h1>REMOVALSPACE.COM</h1></div> <div id="wrapper"> <div id="logo"></div> <div id="menu"> <h2><a href="index.php">Home</a> | <a href="login.php">Advertise with us</a> | <a href="about.php">Read about us</a> | <a href="contact.php">Contact us</a></h2> </div> </div> <div id="content"> There can be no output before trying to sending a HTTP header. Why does the 'check login' file output the HTML header anyways? I would move that to it's own file (header.php or something), and only include it once you have verified their login and completed all your application logic.
-
Re-reading your OP I'm a little unsure what you're trying to do. What element exactly (what's the selector for it) should load in FancyBox, but isn't?
-
The error is claiming the output was started at line 11 in check_login.php - is what you've posted the full contents? Nothing before it?
-
Not quite following what you're saying, but it sounds like you should be normalising the data. It's not difficult, and once you've read about the technique it just makes sense to do it that way. As for your situation though, I don't understand why you would only want to return 1 of the rows? Surely they would all be applicable?
-
You have the jQuery bind defined in the wrong file; $(document).ready(function() { $("a#single_image").fancybox(); }); This should go in the same document where the element exists, getdetail.php.
-
You can use the "DISTINCT" keyword which will only return rows in the database that are unique - that means every column selected has to have the same values for it to be considered a duplicate (i.e. if the ID is different they won't be considered distinct). You should really fix the problem at the source though, and remove the duplication through a technique known as database normalisation.