KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
[SOLVED] JavaScript in PHP loop -- not doing what I need
KevinM1 replied to sw9's topic in Javascript Help
Hi, it's been a while, huh? There are a couple of things going on, from what I can see. 1. The biggest problem is that none of your options have any values. You need to populate all of your select elements' options with the correct video file name for the user to be directed to them. That said, simply doing that will either deliver the user to a blank page where the video plays, or will prompt them to download the file. This may not be what you want. Let me know what your design intentions (i.e., how/where you want the vids to play) are. 2. You're right in that using the typical <a href....> tags isn't a good idea in this case, given the other links on the page. You can create generic HTML buttons to act as triggers, which is a better idea. The JavaScript will be virtually the same, aside for one line of code. A rough idea of it is: JavaScript: <html> <head> <script type="text/javascript"> window.onload = function() { var selects = document.getElementsByTagName("select"); var triggers = document.getElementsByTagName("button"); //<--- note the different line here for(var i = 0; i < triggers.length; i++) { (function() { var trigger = triggers[i]; var currentSelect = selects[i]; trigger.onclick = function() { var selectValue = currentSelect[currentSelect.selectedIndex].value; if(selectValue != "#") { location.href = selectValue; return false; } } })(); } } </script> </head> HTML: <button name="button1" id="trigger1" type="button">WATCH VIDEO</button> The most important attribute for the button tag is its type. Giving it a type of 'button' makes it a simple push button. Giving it a type of 'submit' makes it into a form submit button. Similarly, giving it a type of 'reset' makes it a form reset button. For your needs, simply replace the generic hyperlinks associated with the videos with a generic button element with a type of 'button'. That should ensure that everything is synchronized correctly and that other links on your site don't launch videos. -
1. This is a JavaScript problem, not a PHP problem. 2. You need to show more than two lines of code.
-
Exactly. If you're writing your own library or framework, relative paths make it far easier to keep things portable and extensible. As a matter of immediate practicality, it also saves on a decent amount of typing, which I appreciate.
-
[SOLVED] My first OOP script, not outputting value
KevinM1 replied to keeps21's topic in PHP Coding Help
You're invoking the method wrong, and you're invoking it twice, which is unnecessary. The '$this' keyword should only be used in your class code. It should never be used within your general script. Furthermore, since getComments() returns a value, and does nothing else, you gain nothing by simply calling it without any kind of assignment to a variable. So your line of $in_comment->getComments(); Doesn't do anything of value at all. Try the following lines out for size: $value = $in_comment->getComments(); echo "You said: $value"; -
dont you feel u have disabled them from progressing as there childeren will not be able to install the things they need and therfore u have destroyed an entire generation ? That doesn't make sense... ??? Ubuntu: Destroyer of Worlds.
-
I tend to pseudo-UML my participants. I'll draw the basic skeleton of my systems, then flesh it out as I go. Since I have the artistic ability of a blind gnat, I tend to save the visual component till the end.
-
The new proposed namespace separator "\" is disgusting
KevinM1 replied to emehrkay's topic in Miscellaneous
There is clearly a problem here... Which is where namespace assignment comes into play, with a little help from the global namespace in helping us: namespace Foo { function bar() { echo "namespace Foo"; } } $myNamespace = global::Foo; //to steal an idea from C# class Foo { public static function bar() { echo "class Foo"; } } $myNamespace::bar(); Foo::bar(); To put it another way, other languages implement namespaces using the scope resolution operator. I fail to see why PHP cannot do the same. It all comes down to how Zend wants to overload their existing language constructs. It's still an incredibly stupid idea. It'll completely break all previous scripts and 5.3 is only a minor milestone! It has taken people forever to upgrade to PHP 5 and it introduced far less compatibility issues than doing that would. How long time do you then think it'll take people to adopt 5.3 or indeed 6.0 when it's eventually due? Besides, C# is not dynamically typed, so it cannot be used as an example here. Javascript will just always make it a string and that's fine because it has always done that. Oh, I understand that the logistics of making such a change would be a nightmare. The . operator seems like something PHP stole from Perl, before the decision was made to implement OOP. PHP has worked around it to an extent, using what is typically a pointer dereferencing operator as its standard object-member operator. I think that shows some shortsightedness on Zend's part. A move to a more standard syntax could have helped eliminate the issue we're talking about here. Such a move would have been infinitely more possible between versions 3 and 4 rather than now. Unfortunately, like you say, such a change would be impossible at present. -
The new proposed namespace separator "\" is disgusting
KevinM1 replied to emehrkay's topic in Miscellaneous
You obviously don't understand the problem. You risk ambiguity by doing that. Does it really matter, though? You're either accessing something statically through a class or through a namespace. I fail to see why that would matter. Again, ambiguity. Does '5' + 10 evaluate to int 15 or to string '510'? It's just not possible to overload the + operator to work with string concatenation in PHP as well. Other languages (JavaScript and C# of the top of my head) handle it just fine. There just needs to be a consistent result in cases like that, regardless of what it actually is. So, it wouldn't matter if your case yielded the number 15 or the string 510, so long as it, and all other similar cases, behaved the same way. It's possible, it's just that it's slightly messy because it would require a cast to be thrown in a lot of cases, one way or the other. I can live with that. -
The new proposed namespace separator "\" is disgusting
KevinM1 replied to emehrkay's topic in Miscellaneous
In a perfect world, PHP would do one of two things: 1. Overload the :: operator to work with namespaces. 2. Overload the + operator to concatenate strings, so . could be used in conjunction with namespaces. Option 1 would be ideal, but I wouldn't mind option 2. I always hated using . for string concatenation. The operator itself has no semantic value. Of course, option 2 is out, given the cost and pain it would take to modify scripts to take into account the potential new operator. Unfortunately. Because I really, really hate using . with strings. -
I'm curious as to how you implemented OOP in C. Did you just simulate it with structs? Because, from what I remember, C doesn't have objects. And you're right, pointers in C are a nightmare. It would've been nice if they added some sort of pass by/return by reference capabilities to the language. I agree with you regarding PHP's lack of return type in function signatures. Given that one of the cornerstones of OOP is to program to an interface, it's strange that this aspect of a class' interface isn't available at a glance. Consider the following base class: abstract class BaseExample { public abstract function getId(); } Obviously getId returns an id. That much is made clear by the method name. But what is an id in this context? Is it an auto-incremented integer coming from the database? Is it a string containing both letters and numbers? Is it, itself, an object of some sort, perhaps containing a reference to a collection of specific databases? Documentation obviously helps, but enforcing a return type seems like it would reinforce the encapsulation of data as it adds another system-level guideline on how to implement a class. I dunno...I just think it helps clarify things as it places all of the important info right in the function signature.
-
My cat's breath smells like cat food.* *I'm not very original.** **I don't own a cat, either.
-
Hey DarkWater, not to derail the conversation, but do you have any links that describe what a Router and Dispatcher means in this context? I've used a Front Controller before, but it was a pretty simple setup. Commands were constructed and executed based on raw request info, parsed in my command factory object. I'm just wondering if that's more or less the same thing.
-
One of the things that annoys me about PHP in and of itself is that there's no real logic behind the way its own built-in functions are named. It's very annoying to have errors crop up because, oops, the function you're trying to invoke doesn't have an underscore in its name. Example, with two commonly used functions: htmlentities(); mysql_query(); Either put an underscore in the first, or switch to camelCase, or do something to make it uniform.
-
[quote author=aximbigfan link=topic=112560.msg1020104#msg1020104 date=1224598309] It is interesting but there are SO MANY BUGS in the socket functions. I just wish someone would go in and fix things up a bit. I don't know enough of C to do so, but I would if I could. Chris [/quote] Yeah, C gets messy when pointers come into play. C++ isn't so bad because it has references, but C... yeesh, it can get [b]real[/b] ugly real fast.
-
I've never really bothered with that. I mean, it says right in the declaration whether something is private or not. Further more, I never have any public attributes. They're all either private or protected. For my methods, most of mine tend to be public. Private methods tend to have generic, private-sounding names like init(); Just to discuss other languages (I'm bored, hehe), naming conventions in C#, which I'm currently learning, tend to differ in terms of case. C# has a properties mechanism, whereby you can create getters and setters without declaring a function. So, typically, class code is littered with things like: private string name; private string email; public string Name //note the capital letter { get { return this.name; } set { this.name = value; //value is a keyword, representing the value on the right-side of an assignment statement } } public string Email { get { return this.email; } set { this.email = value; } } So, if you wanted to use these properties, you'd do the following, assuming the class was named Example: Example myExample = new Example(); //C# is strongly typed, so you have to specify the variable's datatype myExample.Name = "Bubba"; myExample.Email = "bubba@bubbagump.com"; Console.WriteLine("My name is {0} and my e-mail address is {1}", myExample.Name, myExample.Email);
-
$_GET is a superglobal (i.e., always accessible) variable that contains the values of the query string passed to the script. What is a query string? Have you ever seen a URI with a structure along the lines of: http://www.somesite.com/contact.php?id=2&post=438 The part after the '?' is the query string. So, let's look at this fictional contact.php script. In order to get to the information in the query string, you simply have to use the $_GET array, like so: $myId = $_GET['id']; $myPost = $_GET['post']; Like DarkWater said, no form is necessary in order to use $_GET. What is necessary is a query string. The reason it works with a form is that when a form is created with its method attribute set to get, the info submitted by the form is sent as a query string to the script that handles the form. In other words, say you have a simple form like: <form name="myForm" action="handleForm.php" method="get"> <input name="name" type="text" value="bubba" /><br /> <input name="email" type="text" value="test" /><br /> <input name="submit" type="submit" value="submit" /> </form> When that form is submitted, the info is passed along as a query string in the URI: http://www.somesite.com/handleForm.php?name=bubba&email=test PHP also has a $_POST array designed to handle form data sent via the post method. The main difference between post and get is that info passed along using post is done behind the scenes rather than being visible in the URI.
-
Nice. :) I haven't played around with sockets yet. Haven't had a reason to, to date. I should, though, because it sounds interesting. Gah! Too many potential projects, too little time.
-
I tend to use camelCase for everything: $someVar; invokedFunction(); $x = new MyAwesomeClass(); Even when I was learning C++ in college, my professors tended to go with camelCase instead of lowercase + underscores. I find it to be easier to read (and type) than using underscores, in any event. All those wasted characters....
-
Yes. Microsoft is the champion of open source design. The champion.
-
Communistic. See: Soviet Union, Cuba, China, et al.
-
that is one ugly cat...lol It looks like some sort of Muppet man-cat.
-
Good points, all the way around. Living in a rural, dare I say, redneck area of the country, the lack of intellectual curiosity and general anti-intellectualism around here is palpable at times. It's not good to be different, and not blend in with the crowd. So, as a wheelchair bound, liberal atheist with a college degree and some programming skill, I don't exactly fit in, despite the fact that I've lived here my entire life. It does lead to some interesting moments, but I digress.
-
So it stops right after the container div's opening tag is rendered? Hmm...how soon is the form displayed after the div is rendered? Is it the first thing, i.e.: <div> <form> . . . </form> </div> or is there more code between the two? Actually, it might also be beneficial to see how that container div is rendered, since everything up to that point works. Also, what kinds of input names work? Is it everything but userEmail and userPassword?
-
1. This has nothing to do with OOP. 2. Since this seems to be a general PHP issue, you should show us your PHP code. Two lines of HTML doesn't help anyone in attempting to diagnose the problem. 3. There is no 3.
-
Well, when only 3% of our national budget goes to education, it's bound to happen. EDIT: Wow...what a crappy top page post.