Jump to content

MasterACE14

Members
  • Posts

    2,687
  • Joined

  • Last visited

Posts posted by MasterACE14

  1. I'm a New/n00b coder myself, and I'll try and explain what the statements mean exactly. *grabs PHP text book*

     

    the "if" statement practically means, if a requirement is met, your block of coding will execute.

     

    the "else" statement practically means, if a requirement isn't met and your coding can't be done , else use the other code(in the curly braces of the else statement)

     

    Format of the Statements(in General)

    if statement

    if ( test-expression ) statement-to-execute-when-true ;

    if else statement

    if ( test-expression ) do-this ; else do-this ;

     

    Examples

    if statement

     

    if ( 10 == 10 ) {  //Meaning, if 10 is equal to 10 (which is true in this example)

    print 1 + 1;    //if 10 == 10 is true (meaning 10 really does equal 10) it will execute the code in the curly

    }                      //braces

     

     

    if else statement

     

    if ( 10 == 11 ) {  //Meaning, if 10 is equal to 11 (which is false in this example)

    print 1 + 1;  // if 10 == 11 is true it will execute the code under the if statement(in the curly braces)

    }

    else

    if ( 11 == 11 ) { //Meaning if 11 is equal to 11 (which is true in the else part of the statement but false in

    print 2 + 2;     //the above if statement)

    }                          // it will execute the code in this if statement(in the curly braces)

     

     

    and as for your coding, I'm not completely sure lol. But that should help you

     

    I hope this helps, that was my 3rd PHP lesson lol,  ;D

     

    I just realised its alittle muddled up, sorry about that. but I think its still understandable.

     

    ACE

  2. woah thorpe, perfect man, Exactly what I want!! and a hell lot simplier! lol.

     

    lol, Love the commenting Barand ;D right up their with the pros! ps. Nice Sig.

     

    what a team you guys make ;D

     

    Keep up the good stuff, PHP Freaks Own the day(so what else is new?  :P )

     

    Thanks again mate! Problem solved  ;D

  3. I have made a Noobie Lottery Number Script and am wondering how do I make it give unique numbers, instead of 2, 3's , or 4 7's etc. Any Ideas?

     

    <?php
    
    $a = rand(1,40);
    $b = rand(1,40);
    $c = rand(1,40);
    $d = rand(1,40);
    $e = rand(1,40);
    $f = rand(1,40);
    $g = rand(1,40);
    $h = rand(1,40);
    
    $space = " ";
    
    $numbers = "Your Lottery Numbers are ";
    
    $result = "$numbers$a$space$b$space$c$space$d$space$e$space$f$space$g$space$h";
    
    echo ("$result");
    
    ?>
    

  4. I guess this is what you are looking for, (this is straight from my PHP 5 text book)

     

    MySQL Data Types

     

    int - An integer from -2147483648 to 2147483647

     

    decimal - A floating point number that can specify the number of permissable digits. For example decimal(3,2) allows -999.99 to 999.99

     

    double - A long double-precision floating point number

     

    date - A date in the YYYY-MM-DD format

     

    time - A time in the HH:MM:SS format

     

    datetime - A combined date and time in the format YYYY-MM-DD HH:MM:SS

     

    year - A year 1901-2155 in either YY or YYYY format

     

    timestamp - Automatic date and time of last record entry

     

    char() - A string of defined fixed length up to 255 characters long. For example, char(100) pads a smaller string to make it 100 characters long

     

    varchar() - A string of defined variable length up to 255 characters long that is stored without padding

     

    text - A string up to 65535 characters long

     

    blob - A binary type for variable data

     

    Hot Tip: An enum type can contain up to 65535 permissible elements.

     

    enum - A single string value from a defined list. For example, enum("red,"green","blue") allows entry of any one of these three colors only

     

    set - A string or multiple strings from a defined list. For example, set("red","green","blue") allows entry of one or more of these three colors

     

    MySQL Field Modifiers

     

    not null - Insists that each record must include data entry in this column

     

    unique - Insists that records may not duplicate any entry in this column

     

    auto_increment - Available only for numeric columns to automatically generate a number that is one more then the previous value in that column

     

    primary key() - Specifies as its argument the name of the column to be used as the primary key for that table. For example, primary key(id)

     

    Hope this Helps. ACE

  5. ok, you would have for example 3 companies, and probably have them in an array.

     

    for this example lets say the 3 company names are, bobs steel. Rocket. and FI(farming Industry)(all made up).

     

    ok, so you got them on a single page, displayed like so.

     

    Companies  -  Rates - Date

     

    Bob's Steel -  $2.00    20/5

    Rocket      -  $2.00    20/5

    FI            -  $2.00    20/5

     

    Have them in a table format like that.

    Now you have a script, that is run by cron every 10 minutes or so.

    The script, first choose's 1 of the 4 prime mathematical operators.( - + * / ) and then

    have 2 randomly generated numbers, within 2 of the initial value of the companies rate.

    and then place the first random number, followed by the randomly chosen mathematical operator, which is followed by the second chosen number.

     

    $math = ("$randnum1 $randop $randnum2");

     

    something like that. it does that, and then displays the new number in the table for each company. so then the table may look like this for example.

     

     

    Companies  -  Rates - Date

     

    Bob's Steel -  $2.23    20/5

    Rocket      -  $1.78    20/5

    FI            -  $2.04    20/5

     

    and it keeps running the cron job every 10 minutes or whatever.

     

    and what I mean by within $2 difference, I mean whatever the math equation above does, it can't go higher or lower then $2 each way of the current rate for that company.

     

    I hope you have a better understanding now. Thanks in advance  :)

     

    Regards MasterACE14

  6. How would you go about creating a Simulation Stock Exchange? I basicly just want, a few companies(made up), and they all have a starting rate of $2.00 , and some how code it so it increases or decreases at a maximum of $2 difference, and is updated say every 10 minutes. and would you need a database for this to work?

  7. Thankyou Both of you.  ;D

     

    I've Tried your script neel_basu, and I get:

     

    Parse error: parse error, unexpected '=' in C:\WebServer\Abyss Web Server\htdocs\phpeval\index.php(52) : eval()'d code(2) : eval()'d code on line 1

     

    "I run it through my PHP testing lab, makes life easier ^^ "

  8. I'm not 100% sure what you mean, but if you mean, you need a way to add something to the beginning, and at the en d of a word, or sentence, you can just use variables.

     

    Example:

    <?php
    
    $prefix = "Beginning|";
    $suffix = "|Ending";
    
    $sentence = "Long story Short. The End";
    
    $result = "$prefix  $sentence . $suffix";
    
    echo($result);
    
    ?>
    

     

    That would display

    Beginning| Long story Short. The End . |Ending

     

  9. hi,

     

    Today I setup a PHP Testing Lab on the net http://phptesting.my10gb.com/index.php go to that, and in the large Text Area, try putting in some coding and it shows what it does below the text box.

     

    With PHP, start by learning the basics. variables, if, if else, switch statements, all the basic statements in general. and

    very first of all learn how the echo function works, and learn other functions.

     

    ok, heres some of the basics.

     

    Lesson 1 - PHP Tags, Echo Function, Commenting, and showing the end of a section of coding.

     

    PHP tags mean, "this is where the code starts, and this is where the code finish's". the "this is where the code starts" tag is this. <?php , so when coding you first put that in. then at the end of your coding/script, you put ?> , and that states that, that is the end of your code/script. Next you need to know what comments are, comments is just parts you can put into your coding, to explain what the coding does, a single line comment starts with // before it, and a multi line starts with /* and ends with */ similar to the PHP tags, commenting is also used for disabling coding. To show the end of 1 little part/section of coding you use the semi-colon character ; . Now onto the Echo Function , well first of all, a function is a large amount of coding, that has been put into 1 basic bit of coding the function. The Most basic function in PHP would probably be the echo function, which is used for displaying stuff on a webpage. The function looks like the following. (also comment examples are in their as well)

     

    <?php 
    
    //This is a single line comment, anything put on this line will not be considered a code/script.
    /* This is a  Multi Line Comment, anything put between
        these commenting tags will not be considered a code/script */
    
    /* Below is the Echo Function, the word "echo" is the name of the function. what you want displayed on the webpage goes in between the brackets and a pair of double comma's, and their is a semi-colon their to show thats the end of the function code/script. */
    
    echo( "Hello World" );
    
    //Below is the Closing PHP tag to show that is the end of all the PHP Coding above.
    ?>
    

     

    on a Web Page the echo function would display.

     

    Hello World

     

    I hope you understand my very FIRST lesson in PHP I have ever done  ;D

     

     

    Lesson 2 - Variables, Basic Maths, and the echo function once again.

     

    Variables are a simple form of storing little bits of information, such as a number, a word, or a phrase, or a combination of each. variables begin with a dollar sign, which tells PHP it is a variable $ , and after it has the name of the variable, you can name a variable whatever you want, as long as it only starts with a letter, although you can put numbers, and underscores in the name of a variable, it must always start with a letter. so an example of a variable and its name would be. it can also be of almost any length.

     

    Correct Syntax (syntax meaning how it is set out.)

    $variable
    $variable_1
    $a
    $my_first_variable
    $variable123
    

     

    Incorrect Syntax

    $123_variable
    $1_variable
    $_variable
    $%#$@%
    $__-
    

     

    Now onto putting data/info into a variable. if you were to assign a number to a variable you could do it in the following way.

    //Note you can use decimals aswell as numbers without decimals.
    /* The Below variables would both be equal because they are both the number 1, although 1 has decimals and 1 doesnt. They are 2 separate variables because their names are different, so they wont be conflicting, you have to remember that no 2 variables can have the same name. and always remember to put the semi-colon at the end of a variable so it doesnt think their is more to the code/script then their really is.
    */
    $variable = 1;
    $variable1 = 1.00;
    

     

    Now, the basic Mathematical Operators(symbols) in PHP are, - is subtract, + is addition, * is multiplication(not x), and / is divide. Now lets make 4 variables, and do a basic maths equation and display it on the page using the echo function. and we will assign a string to 1 of the variables(a string is just text, whether its one word or a sentence).

     

    <?php
    
    $x = 5;
    $y = 2;
    
    $string = "The sum of 5 and 2 is";
    
    $result = "$x + $y";
    $answer = "7";
    
    $combining_them = "$string $answer";
    
    echo($combining_them);
    
    ?>
    

     

    That would display on a Webpage:

     

    The sum of 5 and 2 is 7

     

    And that concludes my First Ever Tutorial on PHP  :) , I hope it helps.

     

    Regards MasterACE14

     

     

     

  10. I was wondering how(thats if it's possible) you can put a Mathematical Operator in a Variable. Let me try and show you what I am trying to explain.

     

     

    The Following Example is what I am trying to do, except instead of using a set Mathematical Operator(The Plus sign in this case) I would like to have the 4 Main Mathematical Operators each in their own variable and have 1 randomly chosen to put in between the x and y variable in the result variable.

    <?php
    $x = 1;
    $y = 1;
    $result = ($x + $y);
    echo("$result");
    
    ?>
    

     

    Something along these lines, even though I know it doesn't work.

     

    <?php
    
    $plus = +;
    $minus = -;
    $divide = /;
    $multiply = *;
    
    rand(variable);
    
    $x = 1;
    $y = 1;
    $result = ($x rand() $y);
    echo("$result");
    
    ?>
    

     

    Something Like that even though I know that, that is way off what it should be. please go easy on me, I'm just a noob  :D

     

    Regards

     

    MasterACE14

×
×
  • 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.