Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Posts posted by shaneg

  1. My site includes a parent-window that has a table of customers. By clicking on a customer, the user initiates the opening of a child-window that has a table of further data for that specific customer. Clicking on a customer in the parent-window runs the following code:


    if(window.varwins["study"+tcustid] && !window.varwins["study"+tcustid].closed){

         alert('A study for this customer, '+tcust+', is already open.');






    This works very well. However, if there is a child-window open, and the parent-window is closed, when the parent-window is reopened there is no longer a connection between the 2 windows and the above code does not keep the child-window from being duplicated in a second child-window for the same customer.


    Is there a way to connect the re-opened parent-window with the already-opened child-window, so that the above code keeps the child-window from being duplicated?


    I think this all has to do with the same-origin policy, but I need to find a work-around.



  2. I have used a couple of your books extensively to develop a couple websites. I don't recall seeing the following topic covered.


    On my current project, I need my users to be able to locate and open a spreadsheet, word, or pdf file that is located (via an in-common cloud server) on their individual, local desktop computer. I don't want the file to open within the website, but instead the spreadsheet file, for example, should open via the software on the desktop, thus allowing the user to be outside of the website and edit or view the file, and then resave it on the desktop (via the cloud server) as appropriate.


    My users all have identical acces to the list of files that are located on the cloud server. All users have access to the same files. The only thing that is centralized on the website is the file reference (that is the same for each user), and the ability to cause that file to be opened.


    Is there a way to do this via javascript?



  3. Function A has called function B, executed a few lines, and now I want to return to function A and execute the underlined part of this:


    function A(){





    function B(){



        return [return true];



    The first return is for function B. The second return is for function A. Of course, I can just put the underlined code in function A after calling function B, but in this case I want to assign the code as a part of the function B return.


    As written, the above code does not work; the second return on the line causes a syntax error. Is there a way to do this?



  4. Per instructions and examples in the book, I am using javascript to initiate use of mysql within a php file to populate the data in a grid within my original javascript file. Everything works fine! However, sometimes, it takes a few seconds for the php file to complete running. I am finding that I need to disable the grid until the php file has completed.


    I know how to disable the grid using jquery $.blockUI(); and re-enable the grid using $.unblockUI(); using javascript commands in my javascript file. But I cannot figure out how to delay the $.unblockUI(); until the php file has completed.


    How can I do that?  Thank you.

  5. Okay, I think I get what you're trying to say, but just for clarification:


    1. When you say "two grids", do you mean two text fields (in a form)?

    I'm using a grid plugin. The plugin is excellent and enables me to do things I don't think I could figure out how to do in PHP alone.

    There are actually 3 grids.

    Grid 1 presents fields from table 1 in the database. These fields are edited by the user. The new data

    is saved in table 1 when the user either exits the grid field or presses enter.

    Grid 2 presents fields from table 2 in the database. These fields are edited by the user. The new data

    is saved in table 2 when the user either exits the grid field or presses enter.

    After editing the fields in Grid 1 and Grid 2, the user then clicks a button that causes the following

    to happen:

    - PHP multiplies fields from table 1 (grid 1) against fields from table 2 (grid 2) and saves the result

    to other fields in table 1.

    - Grid 3 presents the multiplied fields from table 1. Grid 3 is not editable.

    I need the user to see the combination of Grid 1 and Grid 2 OR to see Grid 3, but not at the same time.

    The reason I am saving the multiplied results to table 1 fields is so that I will eventually be able to run a

    query listing table 1 rows, including both the user's inputs as well as the multiplied results.

    2. My assumption is that you're grabbing a bunch of data from two different tables, and then outputting it to various text fields.

    3. From there, the user can perhaps edit the data, and upon pushing a button, can see the result of calculations performed on that data, right?


    Well, if that's the gist of it, you probably don't need PHP at all beyond the initial grab for the data, for which you don't need Ajax. PHP does the initial grab for data to be shown in Grid 1 and Grid 2. But then, after editing Grid 1 and Grid 2, PHP is again needed to go into MySQL and produce the new multiplied results in table 1, for later showing in the non-editable Grid 3. I imagine most (if not all) mathematical operators that are possible in PHP are also possible in JavaScript. As such, you could set up an event in JavaScript to fire when the form is submitted/when a button is pressed, which will then grab the various values from the input fields (in the form), perform calculations on them, and then output that resulting data to a location of your choice.


    If that's what you want to do, I can give you more specifics regarding the code to do so.


    Keep in mind that unless you're going to have to either reinsert/reacquire data from a database after the initial loading of the page, JavaScript alone should suffice, and you won't need PHP/Ajax. Again, PHP/Ajax is needed to calculate the multiplied fields and to then provide those fields for presentation in Grid 3.


    I know there are other ways to do this (there always is, of course). But given the end result I am trying to obtain for the user, I am confident (although, trust me, I am very much listening to all your recommendations and allowing my thinking to be challenged) that the process as I have outlined is what I need to do. The only thing I don't know how to do is initiate the PHP. I can, of course, load a second page and run the PHP independently of the Javascript, but I want to run the PHP by clicking on a button in Javascript so that the user is able to:

    - enter data in Grid 1.

    - enter data in Grid 2.

    - click the button.

    - view the multiplied data in Grid 3.


    Aside from accessing a database midstream, you also generally have to use Ajax to access text files/external websites, as JavaScript is not a very secure language by its very nature.


    Anyway, please let me know if I'm on the right track, and I'll provide you with some starter code that should work for any situation. Thanks.

    Thank you!

  6. I bought the Ajax book, and you're right, it is very good. However, I still have not been able to figure out my problem. I'll try to restate it.

    Step 1: I am using javascript to display 2 grids that allow me to input variables into multiple columns of records in 2 tables of a MySQL database.

    Step 2: I am using php to apply math to variables from table 1 against variables from table 2 in the database and generate a mathematical product which is now saved in another field of the record in table 1.

    Step 3: I then use javascript to redisplay the grid showing table 1, but instead of the variables, I now see the columns of the table resulting from step 2.


    I know how to do step 1, and step 2, and step 3. And I know how to click a button in step 1 that initiates step 3 (three, not two). What I can't figure out is how to make that button initiate step 2 before initiating step 3. In other words, I don't know how to temporarily leave the javascript function of step 1, then briefly go into php to initiate step 2, then automatically return to the javascript function of step 3.


    Currently, I click on the button of step 1 and I do successfully go to step 3, however I haven't run the php in step 2, therefore, my product hasn't been calculated and step 3 shows outdated results if I have made changes in step 1.


    Thanks for your help. You guys are great!

  7. Within a javascript function, if certain conditions are true, I need to utilize MySQL for recalculating some fields, and then return right back into the javascript function. If I use location.href....... as a line in the function which refers to a php file that utilizes MySQL, I can get the calculating done, but I don't get returned back to the function. On the other hand, if go to php within my function and use include...... this will also get the calculating done, and I even then return to the function, but I don't want the php include... to run unless certain conditions are true within the javascript function.


    So, I either need to use something like location.href that also returns me to my javascript function, or I need to be able to keep the php logic from running unless the function conditions are true. I suppose I could do the latter by passing a javascript true/false variable to the php logic, but I can't figure out how to do this, and not even sure if this would work. Within javascript, don't php lines run first and regardless of what is in the function?


    I'm thinking the answer is probably in one of the 2 php/mysql books of yours I have, but I can't think of what it would be.


    Help?? Thanks!

  8. Thank you both so much! I'm digesting the suggestions. Summarizing my objective: There should be only 1 row resulting from $r1. I am then going to use that result to multiply it by a column in several rows resulting from $r2, using this product to update a second column in each of the $r2 rows.


    It looks like I have 3 ways to do this: 1) using "list" outside of mysql (I didn't know about this possibility.) , 2) using "select ... into" within mysql, or 3) using a select statement that includes both tables at once. As I try to figure out the best option, I have 1 other question for now:


    Which of these 3 would be most efficient?



  9. Larry, I have 2 of your books: "PHP 6 and MySQL 5 for Dynamic Web Sites" and "Effortless E-Commerce with PHP and MySQL", but do not have your MySQL book. If I just need to get this book to answer my question, that's fine, but I wasn't sure that my answer would be found there. I have made a lot of progress, but can't figure this out:


    I am needing to get a value from a column in xacres table and multiply it by a value in xinputs table. But I can't figure out how to save the first value as a variable to be used by the SELECT statement for the second table. I have the following:


    $q1 = 'SELECT * FROM xacres WHERE user_id=' . $_SESSION['user_id'] . '&& filler=' . '"Acres owned"' . 'LIMIT 1';

    $r1 = mysqli_query($dbc, $q1);

    if (mysqli_num_rows($r1) >= 1 ) {

    $q2 = 'SELECT * FROM xinputs WHERE user_id=' . $_SESSION['user_id'] . '&& user_id=' . $_SESSION['user_id'];

    $r2 = mysqli_query($dbc, $q2);

    if (mysqli_num_rows($r2) >= 1 ) { .....


    As a test, the above works successfully, but I haven't yet saved the variable from $q1 to be used in $q2. To accomplish this, I have changed the code to the following (where "xacres01" is a column from xacres table and where "owned" is the name of the variable I am trying to save to):


    $q1 = 'SELECT xacres01 INTO owned FROM xacres WHERE user_id=' . $_SESSION['user_id'] . '&& filler=' . '"Acres owned"' . 'LIMIT 1';

    $r1 = mysqli_query($dbc, $q1);

    if (mysqli_num_rows($r1) >= 1 ) {

    $q2 = 'SELECT * FROM xinputs WHERE user_id=' . $_SESSION['user_id'] . '&& user_id=' . $_SESSION['user_id'];

    $r2 = mysqli_query($dbc, $q2);

    if (mysqli_num_rows($r2) >= 1 ) { .....


    All I did was replace "SELECT *" with "SELECT xacres01 INTO owned". And I now get the error: "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" for the 1st mysqli_num_rows line, which I think means I have an error in the preceding 2 lines.


    I don't know if my syntax is incorrect, or if I just need to do this in another way. Can you give me a suggestion? Or is the answer in the MySQL book? Thanks for your help!

  • Create New...