Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. That doesn't explain why it only echoes out the filename rather than the file's content.
  2. Your event handler is already tied to a particular element, so you don't need to reacquire it. Try changing it from document.getElementById(/* your element id */).value to simply this.value.
  3. Returning a value is far different than echoing a value. When you echo a value, it's printed to the screen immediately. When you return a value, you're telling the script that you want to return that value to the scope that contains the function, normally to assign it to a variable. So, something like: $result = sevenDays($days, $usNames); Would store the result of the function in the variable $result. Your current issue is that your function is returning a value, but it's being discarded immediately because you don't store it anywhere.
  4. Ach, sorry...completely missed that. Hmm...and the padding for "status" should be working to. I'm betting at least part of it is that you're using relative positioning.
  5. $row[1] doesn't contain anything because you never actually fetch the results after the query. You need something along the lines of: $row = mysql_fetch_array($results); $_SESSION['firstname'] = $row[1];
  6. KevinM1

    Quick Question

    You can also set element sizes as resolution-dependent values - i.e., as ems instead of pixels.
  7. The box model: http://www.w3.org/TR/CSS2/box.html Since you don't define the padding (or margin) for "content", they're set as that div's content area. Also, you set the width for "status" to be 100%. This means that it's 100% of it's containing element - "content." So, "status" fills up that entire area.
  8. For more on __autoload: http://www.phpfreaks.com/forums/index.php/topic,257613.msg1211970.html#msg1211970
  9. Hmm...I'm not sure where the syntax error would be. Going by the documentation, it looks right: http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html
  10. Try modifying your query to something like: "SELECT * FROM users WHERE user_email = {$_SESSION['user']} ORDER BY full_name"
  11. It looks like your first line is the culprit. You exit the string, then leave a dangling h>r<. You then restart the string with the next double-quote.
  12. It's hard to suggest a particular way to go without knowing your current skill level. Then again, I get the feeling that you're in one of those pesky "I don't even know what I don't understand" phases. I'd say start with the idea of encapsulating your data. Each object should be essentially self-contained - they shouldn't know about the 'main' script, and they should only be able to access other objects' public interfaces (read: public functions). Keep each object as simple as possible. Every object you create should have a specific job. That job itself may be complicated, but you shouldn't overload objects with multiple tasks. You should be able to describe an object in a sentence - "This object does X." If you use the word 'and' more than, say, twice in that sentence, consider breaking the object down into smaller parts. Example: I'm currently writing a web game in another language. I have an object of type CombatEngine. It acts as a facade for the underlying combat system and maintains the overall combat state for the current encounter. Despite the object's internal complexity, I can describe it easily in a sentence. Of course, if you have specific questions, about either theory or code, don't hesitate to ask.
  13. To be honest, it looks like the popup code is buggy. I tried a simple test, and nothing pops up per se...instead, a transparent layer appears at the bottom of my browser pane displaying the filename of the HTML I wanted to appear. There aren't any errors that would trip an error console or Firebug. It's just buggy code. FWIW, I'll post my test code below. <html> <head> <title>Blah</title> <script type="text/javascript" src="packed.js"></script> <script type="text/javascript"> window.onload = function() { TINY.box.show('calendar.html', 0, 350, 350, 1, 2); } </script> </head> <body> Hopefully something will popup </body> </html>
  14. Can I see your code?
  15. Try this: <script type="text/javascript"> window.onload = function() { TINY.box.show('advanced.html', 1, 500, 350, 1) } </script> This will run after the HTML is all loaded.
  16. Nope. It seems like you're confused with how autoload works. Like I said earlier, autoload is a 'magic' function. It's invoked every time you attempt to create an object of a class that hasn't yet been encountered by the script. The argument that's passed to it is the name of the class you want to create an object from. Let's look at an example: $myDog = new Dog(); In our script, no other Dog objects have been created. So, PHP looks at the autoload function to see how to handle it. Thankfully, we have written our own autoload function: function __autoload($className) { require_once("$className"); } How does this work? Well, let's go through it slowly.... function __autoload($className) $className is the name of the class we're trying to instantiate (create an object from). In our case, Dog. { require_once("$className"); } This is the important step. Autoload is a 'magic' function because it assumes some things, and provides some additional, unwritten functionality for us. It assumes that the class provided by $className is also the name of a file that contains that class info for us. So, it automatically adds '.php' to the end of it. That's why it works. So, what happens when this is written: $myDog = new Dog(); $myCat = new Cat(); $myTyrannasaurus = new Tyrannasaurus(); ?? Autoload will automatically include Dog.php, Cat.php, and Tyrannasaurus.php. You just need to make sure your class names and file names are the same.
  17. Hehe It's funny...reading through the JavaScript section, I can always tell who went to w3schools. The same problems crop up again and again.
  18. Ah, I see your problem. Autoload is the name of a 'magic' function. In order for PHP to use it correctly, you need to name it correctly: function __autoload($className) { } Notice the two underscore characters before the word autoload. Now, in order for it to load the correct class, you need to flesh it out: function __autoload($className) { require_once("$className"); } This assumes that all code (the class files and your index.php are in the same directory). Now that that's written, put the function in a file (something like config.php) and include it in whatever script you want (again, in this case index.php) require_once("config.php"); $dog = new dog('dog', 10); $dog->displayname(); $dog->displayAge(); $dog->scream(); So long as everything's in the same directory, it should work. Now, most people tend to put their class code in different directories to keep them portable. There's an easy way to do this. I tend to name my classes like "MP_Base_Exception." The underscores represent directory separators, so the Exception class resides in MP/Base/Exception.php. In order for autoload to get files like that, my function looks like: function __autoload($className) { $path = str_replace('_', DIRECTORY_SEPARATOR, $className); require_once("$path.php"); } So, no matter what class I call, so long as I keep with the convention that underscores = directory separators, I can always obtain the class I'm looking for (provided it exists). Hope this helps.
  19. Short answer: your code is junk. Neither your HTML nor your PHP is intelligible Long answer: your code is junk, but it can be fixed. First, since you're posting your data to the same page that's displaying the form, you should attempt to handle the passed-in data first: <?php if(isset($_POST['submit'])) { $dbc = mysql_connect("localhost", /* never use root as the user */, /* never give out the password on a forum */) OR die("Could not connect to the db"); mysql_select_db("test123") OR die("Could not select correct db"); $query = "INSERT INTO 'test' ('type', 'who', 'why') VALUES ('{$_POST['type']}', '{$_POST['Who']}', '{$_POST['Why']})"; mysql_query($query); } ?> <!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> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p align="left">WHAT<br /> <select name="type" size="2"> <option value="ONE">ONE</option> <option value="TWO">TWO</option> <option value="THREE">THREE</option> </select> <br /> WHO<br /> <input name="Who" type="text" value="Who" size="40" maxlength="50" /> <br /> WHY<br /> <input name="Why" type="text" value="Why" size="40" maxlength="50" /> <br /> <input type="Submit" name="submit" value="Submit"> </p> </form> </body> </html> I noticed that you're trying to access form inputs as direct variables (i.e., as $submit rather than $_POST['submit']). You can't do that unless register_globals is turned on in your php.ini file. Turning this on is a BAD IDEA as it leads to both a host of security problems and complicates the long-term maintenance of your code. Access form variables the right way, through the various superglobal arrays ($_POST and $_GET). You should also look into validating and securing incoming data. You should always treat user supplied data as a security risk, and only accept it after it's been validated.
  20. How did you write your autoload function?
  21. I'm assuming that the content you want to stick into the variable named 'content' is the HTML. If so, you need to stick it in a string (read: inside of quotes) and concatenate it to what you already have using the '+' operator: content += "<td class=\"daydate\"><a href=\"javascript:void(0);\" onClick=\"javascript:setDate(" + i + ");\">" + i + "</a></td>"; You'll need to do that for all of your dangling HTML.
  22. As an aside, I wouldn't recommend that site for attempting to learn JavaScript. It barely covers the bare-bones basics, and favors a coding style that I feel leads to long term problems if adopted.
  23. No to speak for Daniel, but yeah, that's a good way to look at it. There are essentially two components at play here - syntax and semantics. Syntax is the form and grammar of a language - which symbols are important, how they go together to form language structures (expressions, blocks, objects), etc. The semantics are the meaning of what you're trying to do - validating user input, accessing the db, etc. When you're learning to program, it's important to try to separate the two. For example, you can access a database in PHP, Ruby, Java, C#, etc. But how you do it - the syntax - changes from language to language. As far as resources go, I think that this board is one of the best. The reason is that you get to see real world problems, and, even better, real solutions to them. It's far better than an author writing "Here's a canned example, set up from the outset as a failure, and now I'm going to fix it." Not only that, but, aside from the PHP online manual, this board is also the best place to get ideas on what constitutes best practices. You should also code as often as you can. To use an analogy myself, it's like converting to a healthier lifestyle. Dieting alone won't cut it - you need to exercise as well. There's no substitute for actually getting your hands dirty and writing code.
  24. Figured it out. To use an exponent in JavaScript, you need to use: Math.pow(a, b); //a^b The '^' isn't an exponent operator in this language. EDIT: Working test code: <html> <head> <title>Blah</title> <script type="text/javascript"> function decToBin(num) { var bits = []; var dividend = num; var remainder = 0; while(dividend >= 2) { remainder = dividend % 2; bits.push(remainder); dividend = (dividend - remainder) / 2; } bits.push(dividend); bits.reverse(); return bits.join(""); } window.onload = function() { var checkboxes = document.getElementsByTagName("input"); var checkboxesLength = checkboxes.length; var decResults = document.getElementById("decResults"); var binResults = document.getElementById("binResults"); for(var i = 0; i < checkboxesLength; i++) { checkboxes[i].onclick = function() { var results = 0; for(var j = 0; j < checkboxesLength; j++) { if(checkboxes[j].checked) { results += Math.pow(2, j); } } decResults.innerHTML = "Decimal number: " + results; binResults.innerHTML = "Binary equivalent: " + decToBin(results); }; } } </script> </head> <body> <form action="#" method="post"> 1 <input type="checkbox" name="binary" /> 2 <input type="checkbox" name="binary" /> 3 <input type="checkbox" name="binary" /> 4 <input type="checkbox" name="binary" /> 5 <input type="checkbox" name="binary" /> 6 <input type="checkbox" name="binary" /> 7 <input type="checkbox" name="binary" /> 8 <input type="checkbox" name="binary" /> </form> <div id="decResults"></div> <div id="binResults"></div> </body> </html>
  25. Why are you subtracting at the end of your validation function? calcCV21 already returns the accumulated binary value based on what's been checked.
×
×
  • 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.