Jump to content

YigalB

Members
  • Posts

    56
  • Joined

  • Last visited

    Never

Posts posted by YigalB

  1. I wrote a short quiz in which PHP code creates a mathematical question based on random parameters.

    The intention was to let JS to check the user's answers (via form) and compare it to the required results.

     

    How can I pass the required data from PHP to the JS? After all, PHP variables are not recognized by the client side when executing the JS.

     

     

  2. Here's a rudimentary sample to graph y = Ax + B.

     

    When drawing charts you'll find most of the effort goes into things like axis scaling, axis labels, legends etc (so I missed these out). There is a baaChart link in my sig if you need more.

     

     

     

    Save it as say, "mygraph.php" and display it on another page using an img tag EG

     

    Thanks!

    Looks like a nice start. I will try using it as a base example.

     

  3. Thanks, I understand.

    I was sure there is a "ready to use" graph drawing function, but I guess I was wrong.

    So if i need to step back and learn, what would you recommend a newbie like me to do in order to reach the graph drawing?

     

    BTW - the target is educational.

  4. I would like to show a function graph embedded with other content on the web page.

     

    At first, it should be a linear line, such as y=aX+b.

    later I would like to extend it to parabola, sinus etc.

     

    Can someone recommend how to do it (hopefully with example), with ability to set start point, end point, the resolution of the function (every integer, every tenth of integer etc), and also how to draw the X & Y axis.

  5. Can you log into the MySQL console?

     

    Windows:

    ->cmd

    ->cd (to your mysql directory) ex. wamp is C:/wamp/bin/mysql/mysql(version)/bin/

    ->mysql -u php24sql -p;

     

    it will prompt you for a password.  If you are not using one, hit enter and it will let you in, or throw an error.

     

    I hope this was clear for you. 

     

    *note, if you are using wampserver, you can just choose the mysql console from the tray.

     

    Thanks!

    I am using XAMPP.

    I followed your guide lines and got:

    ERROR 1045 (28000): Access denied for user 'php24sql'@'localhost' (using password: YES)

     

    Then I re-entered the original password - and it worked! Thanks !

     

    I am not sure what happen, because I marked "no password" and "go" at phpMyAdmin, but now it seems the need for password is still there.

  6. I am learning mysql using an example.

     

    According to the guidelines, I created a table and I was trying to access it with the following code:

    <?php
    define("MYSQLUSER", "php24sql");
    define("MYSQLPASS", "");
    define("HOSTNAME", "localhost");
    define("MYSQLDB", "smithside");
    
    $connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
    if ($connection->connect_error) {
    die('Connect Error: ' . $connection->connect_error);
    }
    else {
        echo 'Successful connection to MySQL <br />';
        if ($result = $connection->query("SHOW TABLES")) {
            $count =$result->num_rows;
            echo "Tables: ($count)<br />";
            while ($row = $result->fetch_array()) {
                echo $row[0]. '<br />';
                }
            }
        }

     

    I got the following error:

    Connect Error: Access denied for user 'php24sql'@'localhost' (using password: NO)

     

    At first, I was sure it's the password, so I changed to "no password" using phpMyAdmin, but I still get the above error.

     

    Here is what I see at phMyAdmin:

    Users having access to "smithside"

    User Host Type Privileges Grant Action

    php24sql % global SELECT, INSERT, UPDATE, DELETE No Edit Privileges

    php24sql localhost global SELECT, INSERT, UPDATE, DELETE No Edit Privileges

    root linux global ALL PRIVILEGES Yes Edit Privileges

    root localhost global ALL PRIVILEGES Yes Edit Privileges

     

     

  7. Running this JS code:

    <script type="text/javascript" language="javascript">
    document.write("Using: " + navigator.appName + "</p>");
    document.write("Version: " + navigator.appVersion + "</p>");

     

    The result was:

    Using: Netscape
    Version: 5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2

     

    Why did I get Netscape when I am actually using Chrom?

    And the version response includes Apple?

  8. While trying to run very simple code of javascript from within PHP, it runs when the code is:

    <h2>My header</h2>
    <script language = 'javascript'>;
    alert('here I am');
    </script>
    
    <?php
    echo "starting Now <BR>";

     

    But when the code is:

     

    <h2>My header</h2>
    <script language = 'javascript'>;
    document.write(“xxxx”);
    alert('here I am');
    </script>
    
    <?php
    echo "starting Now <BR>";

     

    It fails to run the js code, and also the alert is not executed.

    The only thing I added was

    document.write(“xxxx”);

    What did I miss?

  9. We're not here to write your scripts for you. Best advice I can you give you would be to use jQuery - it makes manipulating the DOM and AJAX requests simple.

     

    First read up on selectors and events, and how you can use them to get the value of your inputs and capture the form submission. JavaScript is C-based syntax, like PHP, so you should be able to work out the basic syntax for the validation pretty easily. Then for AJAX requests just use the AJAX API.

     

    Thank you for your kind guidance.

    At this stage I just need an example so I could duplicate and modify according my exact need.

  10. I would prefer to use CSS for this, as it makes the code a little more robust and easy to maintain. CSS has a property for this called the "direction" property which has three possible values: ltr (left to right, default), rtl (right to left) and inherit meaning it inherits the direction property from its parent element. As ManiacDan stated, a class for this can be made and be assigned to any text that you want this to affect. There are several ways to implement the ltr, rtl change as well.

     

    Thanks. I like the idea, and I will try it.

     

    What about the text itself?

    For example, on  a certain page I will need to display a content/ For example, write a "Hello" in case of L2R, or the same word in a different language R2L.

    Should I have many "if" statements in the code, so the server will send the right word according to the $direction variable?

    O

     

  11. A math quiz is presented and the user should fill the form cells with the answers.

    So far I did it with PHP and it works well, until I learned about Ajax existence. But I failed to make it work.

     

    I would appreciate an example of code for the following:

    - A form with two cells for numerical: a, b.

    - Once the user press "submit", each cell is tested for the expected results: a should be 5, be should be 7

    - if a is correct, the boundary of the cell becomes green, and the grade 50% appears in a circle near by. If not, the boundary becomes red and the grade appears 0.

    - same for b

    - bellow both appears the final grade a+b in circle

    - 2 parameters are sent back to the the PHP code: true/false for a, and true/false for

     

    Thank you!

     

  12. Thanks. It is useful.

     

    But the main challenge I have is how to approach the web site design when it could be used by R2L or by L2R users.

    Should I duplicated the pages? this will cause maintenance to be painful.

     

    Should I have a parameter which will indicate R2L or L2R and have many IF with in the pages?

    This will make the code less readable.

     

    Is there a recommended solution?

  13. In order to display an equation of parabola, I copied from somewhere

    	<span style="font-size: 200%"><span class="math"><b><var>y</var>  
    = <var><?php echo "$a" ?></var><var>x</var><sup>2</sup> <?php echo "$sb"?> 
    <var><?php echo "$b" ?></var><var>x</var> <?php echo "$sc"?> 
    <var><?php echo "$c" ?></var></b></span></span> 
    </p> 
    <br> 

     

    It doesn't look nice, and also it doesn't know how to eliminate parts when the parameter is zero.

    For example, in the case of y=ax^2+bx+c, and a=1 b=0 c=5, it would print y=1x^2+0x+5, instead of y=x^2+5

    I could do pre-processing and solve it, but I was wondering if there is a nicer way to do that?

  14. you can use round

    round is risky because of the gray area between rounding up and down.

     

    how is rounding to the hundredths place any more risky then multiply the number by 100?

    Maybe I am wrong, but if multiply by 100 and truncate after the dot, I get exactly the same digits as was in the source.

    I am not sure what would round do if the exact result should be 14.055 and the user types 14.05. would it round the same?

     

    One thing is sure - if I multiply both by 100 and truncate, the result would be 1405 for both.

  15. there are several different types of inputs, the one that allows a user to fill in the field with whatever data if type='text' (assuming we aren't including textareas).

     

    if you want to validate the user data in real-time before they submit, javascript would be required.

     

    once the user submits, you can compare the data however you want and return whatever feedback you want. also, why not simply compare the floats?

    The reason I can;t compare the floats is that the "correct answer" may have endless digits after the point. I.e the correct answer is: 42.377764

    I don't want the user to type all the least significant digits, so it seems to me that two are enough.

    If I compare 42. 37 and 42.377764 it would be considered as different answer.

     

  16. A form needs to get answers of math quiz, returning numbers, up to 2 digits after the point.

    In all form examples I noticed the usage of: 

    ...<input type="text" name="name" /...

     

    Cant it be a number? floating or integer? why "text" ?

     

    Also, can I limit the form to accept numerical input only or would I need to learn Ajax for that?

     

    Once I have the answer, I need to compare it to the correct answer. The method I have in mind is to multiply the answer and the correct one by 100 and compare the integer part. Is there a pre-made function that can do the same?

  17. How can I make the program to stop when the client tab is terminated?

    It depends on 'ignore_user_abort' setting in php.ini. If it's set to TRUE your script would work until processing is finished. If set to FALSE processing is terminated.

    You may change default behavior via function ignore_user_abort() http://www.php.net/manual/en/function.ignore-user-abort.php

     

    In your case when you noticed that "the program continued from where it stopped"... Maybe your browser took it from the cash?

    It could be the browser took it from the cache. How can I prevent that?

     

    Also, i just added a "die" statement in my code, and was hoping that after that, if I refreshed the browser window, it would go back to the beginning.

    The browser actually continued executing the code.

    Is it again because of the cache?

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