Jump to content

SnapGravy

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by SnapGravy

  1. Hi there! I just wanted to ask/talk about something that has been bugging me. Since I started programming, I have utterly fallen in love with it. Ive spent many years doing design and simple HTML and found myself to not be naturally gifted when it comes to visual design (although I love seeing great works of art I can't really get myself to produce great works of art myself). But when I started coding, I noticed how fast and how fun it was, I have been writing stories and books for a long time and I kind of figured. I cannot paint with a brush, but I can paint with words. I cannot design beautiful website but I can make them beautiful with words(code). Anyways, the real issue at hand. There are many frameworks for JavaScript, one of the more popular ones jQuery. I see it mentioned everywhere, and here is where my annoyance start. For me looking at jQuery its simpler, faster and produced great results but I am thinking it's still just a framework. Someone wrote that framework in JavaScript, so to me a person who simply uses only the framework might not appreciate or really know the underlying language its built upon. This is of course just personal opinion on the subject, personally I like to build my own frameworks/functions/objects from scratch to aid in my scripting without relying on frameworks. I always challenge myself to produce the same results you see on other cool websites without relying on frameworks and rather build everything from ground up. So my question is, am I stupid? Should I hunker down and just take the easy way or keep to the Vanilla and keep going in the direction I feel is right. I know I want to focus on building it by myself from scratch, I just wonder if I am being thick headed by doing it? If you have time, leave your opinion on the matter. Id like to hear your thoughts!
  2. Thanks for the lesson It is really appreciated and il start making the kittens happy.
  3. I'm kind of happy that you mention this because I really don't like passing global's like this either. But from countless searches I have found no other way to create communication between two classes except for extending the class. I could do this but if I have multiple classes I cannot extend them all. I could of course write the methods I use from other classes inside the actual class but then I will end up having duplicate methods in several different classes which for me is bad because if I want to change the method I need to do this over all the classes making creating the method in the first place moot. I am not an expert though, and I would be extremely happy if you have a pointer for me in how to go about this problem sharing methods from multiple classes. That's been the one point about OOP that's baffled my mind and the only way I found a way to do that was to global the object so I can use it within a class. (Not trying to hijack this topic with my own question but since its in the spirit of learning and were already on the subject. Hope you don't mind OP).
  4. Well what you wrote there is correct. You don't strictly need to use a constructor though. Personally I only use constructors when I want to pass predefined values from a database to an object. (Kind of like I need to set class variables before I start using it). If I am passing outside values into my class I usually just make methods for it. class myClass { public classVariable; // These are local to the class and can be used by all methods/functions public function myMethod($localMethodVar) { $localMethodVar2 = $localMethodVar; // These are local to the method and can only be used within the method/function $this->classVariable = $localMethodVar2; // This assigns local method variables to classVariable } public function myMethod2() { $localMethodVar = $this->classVariable; // This takes classVariable previously assigned a value by myMethod and puts it in localMethodVar local to myMethod2 } } In your original code there is some variables being called that is outside of their scopes etc. As you pointed out in your last reply, when creating a class one should keep some points in mind. Class variables shared by several methods should be defined beforehand even if they are empty. classVariables are local to the class and can be used by all methods in your class. methodVariables are local to the method and is only used in the method. if you want to use methods from another class file after the object has been created you can call functions by first declaring the object. global $object; then you can call a method from that object using $object->objectMethod(); This is how I understand it through my own studies. Once the object oriented aspects dawns on your completely a whole new world opens up in programming. (When I burst that bubble it was definitely eureka going on) If this doesn't really help you any i'm sorry for creating a bigger confusion. Good luck onwards!
  5. Sorry messed up in my comment there, edit your acceleration function public function acceleration() { echo count($this->distance); return ($this->speed[2] - $this->speed[1])/5; // and the acceleration (if constant) is difference of speed at different time points }
  6. You are still trying to pass 3 variables into the constructor and therefore needs 3 variables to receive it (as far as I know) like Thorpe mentioned. You could make the array before passing it to your constructor though. $v1 = 10; $v2 = 20; $v3 = 40; $distance = array($v1, $v2, $v3); $object = new Motorbike($distance); echo '<p>The speeds are ' . $object->acceleration() . '</p>'; class Motorbike extends Vehicle { private $wheels, $price, $builtyear, $seats; private $distance; private $speed = array(); function __construct($distance) { $this->distance = $distance; for($i = 1; $i<=3;$i++ ){ $this->speed[$i] = ($distance[$i])/($i*10); // this gets the distances sent by the object, divides them by different time points gets the speed } } public function acceleration() { $devuelve = array(); echo count($this->distance); return $devuelve = ($this->speed[2] - $this->speed[1])/5; // and the acceleration (if constant) is difference of speed at different time points } }
  7. Sharp eyes goes to PFMaBiSmAd Also make sure you got session_start() somewhere for the user, i didnt see it on your page. Might be somewhere external though.
  8. Try <?php if(isset($_POST['submit'])) { $firstname = $_POST['first']; $lastname = $_POST['last']; $dob = $_POST['dob']; $gender = $_POST['gender']; $result = mysql_query("UPDATE users SET firstname = '{$firstname}', lastname = '{$lastname}', dob = '{$dob}', gender='{$gender}' WHERE username = '{$currentUser}'") or die(mysql_error()); if($result) { echo "your information was updated in the database and is as follows<br />"; //put the results on the screen echo "<br />{$firstname}<br />"; echo "<br />{$lastname}<br />"; echo "<br />{$dob}<br />"; echo "<br />{$gender}<br />"; } else { echo "error, could not update your info to the database<br />"; } } ?> <html> <body> <form method="post" target="_self" action=""> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="submit" value="Add personal information to database" /> <input type="reset" value="Reset fields" /> </form> <p><a href="index.php">HOME</a></p> </body> </html> I don't know if this will help you though, I copied your code and edited a little. Make sure you double check your variables and whats going into your database as one symbol or letter can break everything.
  9. You need to echo the ID to get it to show in the address bar. Any code you want to output from PHP needs a command to print it out. (As far as I know) Also forgot some curlies in there (I believe). <a href="http://microlight.co/vince_php/printcard.php?id=<?php echo $id ?>">Printable Card</a> if (!isset($id)) { $id = $_GET['id']; }
  10. I dont know if youve already tried this but on my site I create global JS variables from PHP like this. <script><?php getVariable() ?></script> <?php function getVariable() { // Some generated code to add to the variable echo "var jsVar = {$generated_php}"; } ?> Might not be what you meant, hope it helps.
  11. I don't know if this will help but here is one example that might work. Usually I use SPAN to populate from AJAX. You can place it anywhere you want and have it return new values. For example you can put the options between a span and have the options change etc. Sorry if it doesn't help you any. HTML ------- <span id="box1"> <select onchange="nextCombo(mySqlID)"> <option value="1">1</option> <option value="2">2</option> </select> </span> <span id="box2"></span> Ajax ------ function nextCombo(mySqlID) { ajax("box2", "getresult.php?boxcategory=", mySqlID); } function ajax(element, target, value) { ajax = new XMLHttpRequest(); ajax.onreadystatechange = function() { if (ajax.readyState == 4 && ajax.status == 200) { document.getElementById(element).innerHTML = ajax.responseText; } } ajax.open("GET", target + value, true); ajax.send(null); } PHP ------ <?php if (isset($_GET['boxcategory'])) { // MYSQL COMMANDS HERE TO DRAW DOWN NEEDED INFORMATION FROM DATABASE ?> <select onchange="nextCombo2(mySqlID)"> <option value="next1">next1</option> <option value="next2">next2</option> </select> <?php } ?>
×
×
  • 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.