Jump to content

noidtluom

Members
  • Posts

    51
  • Joined

  • Last visited

    Never

Everything posted by noidtluom

  1. Since I don't know "J2EE, Coldfusion, ASP, and RoR" I'm probably not the best person to ask, but from my experience I find PHP to be a seriously powerful language. I'm not surprised if Yahoo is using it to make their site. I believe people should be more open towards these sorts of things. PHP is one example, and HTML (yeah, that's right, I said HTML). Another is to do with programs, such as Blender3D. It's open-source, about 10MB, free, and has got probably all the features that packages like 3DSMax and Maya stuffed into it. The works done with it are amazing.
  2. Why don't you try the search and replace function on your text editor. The text editor I use (PSPad) has a pretty useful feature where when you are doing search and replace. You can ask it to prompt you for each replace. So I tell it to do a general replace, and just click yes/no. It gets the job done pretty quickly. Don't worry, I'm sure every single programmer has once done mindlessly boring work like that. I sure have.
  3. I might not fully understand your question, sorry, but here is my go at answering it: Size? I think you mean maxlength? Size is the width of the input field. Maxlength is the number of characters allowed to be typed in it. Try: <form action='' method='post'> <input type=text name=test maxlength=200> <!-- feel free to change 200 I'm just giving an example --> <input type=submit name=submit value=submit> <!-- and then (if you want action='' on the same page then just do if(submit). --> <?php $myVarTest=$_POST[test]; // I would recommend you run a security function on this variable though. echo $myVarTest; ?> Sorry if my code isn't that neat, it is just a quick example.
  4. OK my conclusion is that calling a variable with it can only be done with PHP 5. Since I want my application to be PHP 4 compatible I guess I will have to stick to this: <?php function example() { echo "I am the original function A::example().<br />\n"; } ?> Then just call the Class::example(); Oh well. Solved. (at least)
  5. Hmm I was viewing a different scope page. I'm now pretty confused because in the example it shows this: <?php class Foo { public static $my_static = 'foo'; public function staticValue() { return self::$my_static; } } ?> As you can see $variables are used there perfectly fine. As a note, in PHP 4 you cannot define as public. So I'm quite confused how to actually define a static or const variable to start with. For reference you can read the note on that page which I found useful and slightly contradictory: Any help? Thanks in advance.
  6. Try change ($free) into $free - Take away the brackets around it.
  7. Nope, still not working. By the way, I don't think you can do "echo Dog::DogConstructor;". It should be "Dog::DogConstructor();". Also, in PHP 4 the constructor is basically function nameOfMyClass, so function DogConstructor wouldn't technically be the constructor. Can anybody do a simple example using :: for both a function and a variable that works in PHP 4? I will really appreciate that. That should also solve my problem Thanks in advance. Awaiting your useful replies!
  8. You might have misunderstood me. That is exactly what I am trying to escape. I am trying to call a variable or function in the class without creating a new instance. I thought that the "::" operator could do that? Oh, and in PHP 4 it has to be defined in the constructor I think.
  9. You should do: if magic quotes is not on, then perform the slashes functions. Otherwise, just leave it up to magic quotes.
  10. Just been using this :: recently and came across this problem and unable to fix it. NOTE: I am using PHP 4. <?php class Dog { // constructor function Dog() { // BEGIN constructor static $myString = 'Seriously totally awesome'; } // END constructor } // END class Dog echo Dog::$myString; ?> The "echo Dog::$myString doesn't work. I am getting this error: The line with the error is the one that contains "echo Dog::$myString;". Just as an extra note, I can do Dog::myFunction(); without any errors.
  11. Use mysql_num_rows to check how many rows you get. Then if (mysql_num_rows($SQL) == 0) { echo 'No results'; }
  12. Well for your second question, what I would do (which is pretty unorthodox) is after an include, set a variable or constant. For example: if($incMyFile!=1) { include_once 'myfile.php'; $incMyFile=1;} I don't know of a function sorry. EDIT: oh, especially if your included file defines constants or important variables, just do if MYIMPORTANTCONSTANT is defined then don't include it the next time.
  13. It is correct. Basically he wanted to set those $this->var in the Class all the same value, as well as the _SESSION. For example instead of doing: <?php $var1=1; $var2=1; $var3=1; ?> You can just do: <?php $var1=$var2=$var3=1; ?> Sorry for the lack of neatness in PHP coding I'm not normally like that unless I'm giving a quick example.
  14. I think you'd find better at the freelancing category.
  15. To give a little bit more information on the second question: If possible I would really like a site or something that can easily explain controllers (hopefully with examples included) for PHP (specific) for complete beginners. I like those Currently what I have been doing is having an index.php which included a template, and where the content should be I filled it full of <? if ($page=="home") { include ""; } elseif ... etc ?> And to prettify the URLs I would use mod_rewrite so that instead of site.com/index.php?page=mypage (for example) it'll be something like site.com/mypage. However, after hearing about controllers, I feel maybe this isn't the best method. If there isn't a website/tutorial which can explain it for beginners, I would appreciate some example files for the most basic controller system. Thanks in advance.
  16. Wow I actually answered somebody else's question online. That's a first for PHP. Well, considering this is my first PHP forum.
  17. Well, even though I still am confused with your question, I think for a start that you can do something like <?php <?php ?> ?>...basically, don't put another <?php inside a <?php.
  18. You mean concatenation? Why don't you just do echo '<table><tr><td>.'$i.'</td> <td> '; $SESSION['myday'] = $i echo ' </td> </tr> </table>'; Sorry if I misunderstand your question.
  19. Apache I think. Go into your .htaccess and add: RewriteEngine on RewriteBase / Then for every page add: ReWriteRule ^animationautomation/$ home1.php?sub_cat_id=1 ReWriteRule ^animationautomation$ home1.php?sub_cat_id=1 In case you might want to send variables over the URL you might want to look at this code as well, it's pretty self explanatory: By the way, the below code is only for sending integer variables. This is useful for pages which you want to limit the variable. ReWriteRule ^mypage/([0-9]+)/$ index.php?p=mypage&id=$1 ReWriteRule ^mypage/([0-9]+)$ index.php?p=mypage&id=$1 So if you want to send two variables for example you can try: ReWriteRule ^mypage/([0-9]+)/([0-9]+)/$ index.php?p=mypage&id=$1&foo=$2 ReWriteRule ^mypage/([0-9]+)/([0-9]+)$ index.php?p=mypage&id=$1&foo=$2 And so 3 variables, go to $3, and so forth. For others you might want to use "(.*)" (without quotes). Sorry if I made a mistake (to those professionals) feel free to correct me. I hope I didn't misunderstand your question.
  20. I have recently learnt OOP and Classes. Time for my first question. I have a simple database fetch: $result = mysql_query($query); if ( mysql_num_rows($result) > 0 ) { // now let's use the while function to repeat while ( $row = mysql_fetch_object($result) ) { echo $row->id .' is '. $row->username .'<br />'; } } else { echo $error; } As part of OOP, (well, it's more of a classes question that's why I didn't put it in the OOP child board) I decided to try and put this into a class where I can call it anytime. However, I'm not too sure how to do this. This was my try (obviously this function is in a class {} ): function Query($query,$structure,$error) { $result = mysql_query($query); if ( mysql_num_rows($result) > 0 ) { // now let's use the while function to repeat while ( $row = mysql_fetch_object($result) ) { echo $row->id .' is '. $row->username .'<br />'; } } else { echo $error; } } I was thinking of being able to 1) specify the query (hence $query in the function), 2) specify the structure of the output and 3) Easily customize error message. I don't always want it to say "No Rows Found" or something like that. For example in the inbox I would want it to say "No messages" if there were no rows, and in the forum profile checking the number of submissions I would want it to say something like "No submissions." You get the idea. I'm having a problem with 2). I don't know how to specify the structure. Or is there a better way to do it? OK, for my second question, I've heard about controllers recently and I would like to learn how it works. Can anybody link me to a guide? I would hopefully like one without a .htaccess (unless you can provide a .htaccess with a script which you want to allow people to download). I'm not too sure how to layout my files. Thanks in advance, and awaiting your helpful replies!
  21. Thank you. I'm sorry I didn't really understand your sentence. Which one is faster, the " or ' ? and which one do you think is easier to read? I got confused with the use of "it" in your sentences. Have you also got an answer for the difference between echo (""); and echo ""; ? and which should be used? Thanks in advance.
  22. Since I am trying to improve my code optimization, I have some simple questions. Is there any difference between echo (""); and echo ""; and which one is better to use? Should I use echo "$var is a very cool variable and so is $anothervar"; or echo $var ." is a very cool variable and so is ". $anothervar; or echo $var ," is a very cool variable and so is ", $anothervar; and if possible, why? Also, is there any suggestions for naming variables? I normally just name them $whatever $i $want. (of course, if the variable contains a username I name it something like $username.) So is there any sort of format that should be used? I think I read somewhere that they should be (of course, not mandatory) named like this: $twoWords or $anotherVariable, where the second word's first letter is capitalized. Thanks in advance.
  23. I do not see anything immediately wrong with it, but from what I normally do to fix "invisible" errors to to copy over working code from something else, and just replace the variable.
×
×
  • 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.