Jump to content

phppup

Members
  • Posts

    862
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by phppup

  1. @ginerjm I am not a code by either profession or training. More like an overzealous hobbyist.

    And while I understand your example, it's not something that I would have thought of myself, nor have I seen examples like it in my search engine queries.

    So, thanks.

    Now the question is, how (if possible) would I avoid JavaScript and have PHP pull results from those resulting lines in your example?

    My current thought process is to use document.querySelector in order to loop through and pull data to use on a new script.

     

    @Barand Admittedly, this is something that came up AFTER implementation of other ideas, so it may be a backwards approach.

    But for now, it's (hopefully) easier than re-structuring my other files. 

    So, getting info that already exists and re-using it in this manner just might work.

     

     

  2. I'm trying to gain access to a file for the purpose of extracting a portion of it for use with JavaScript.

    If there's an advisable methodology that can be shared, that would be GREAT.

    The best that I've come up with is to use readfile("sample.php"); to gain access to the data.

    However, I then want to run a JavaScript on this data.

    Is there a recommended way to accomplish this?

    The only way I can think of is to move the data into a variable, but my effort has a bug.

     

    echo readfile("sample.php");  //provides a viable result
    
    //but then...
    $my_variable = readfile("sample.php");
    
    echo $my_variable;          //provides a number (I have not determined what that number represents... perhaps a line or character count??)

     

    //Note: print_r($my_variable)  provides same result

     

    How can I achieve  a successful result and transfer the data so that JavaScript can affect it?

  3. My code is a mess from various attempts at a simple task (it is embarrassing). And also frustrating (especially since my searching hasn't found a solution, or a more important explanation of WHY a method works).

    I want to have my stay contents displayed in a specific HTML container.

     

    fruits = ["apple", "orange", "cherry"];
    
    x = document.getElementById("myList").innerHTML;
    
    for (x = 0; x< fruits. length; x++){
      
    document.getElementById("demo").innerHTML = x;
      
      }

    I need a solution. And would appreciate comments for educational understanding.

     

    Thanks.

  4. Well, I'm not sure (because the whole point was to minimize code lines... LOL).

    And this was just a personal effort to see where it might lead me.

    I wouldn't have thought of using INCLUDES and I don't do well when I lose track of my (visible) code.

    The funny thing about this little project is that the"variables" are probably the most "constant" piece of the puzzle.

    That's why I thought FUNCTIONS would be a good step.

    In essence, some might be considered late after 5 minutes, others are 10. Some after 30, others 120.  Hence, a different (short) function for each scenario. 

    Essentially, the messages are the same: Your late, your very late, see your supervisor, go home fool, etc. regardless of "group."

    I'm still considering my options, and the other factors that might guide me.

    No hurry for this one.

  5. @ginerjmYes, and I appreciate your input.

    But the solution means that I have to include the array in every redundancy of similar functions that will use those variables.

    Without using functions at all,I can list the variables once and write straight code.

    Either way, something will be repeated, so I have to re-evaluate.

    At least NOW, I can make an informed decision.

  6. Just did more reading and I'll have to review my implementation.

    It seems that my attept to reduce (already short) code repetition will result in an increase of duplicated variable lists.

    But the effort was a learning experience.

    Thanks for the responses.

  7. I think I'd prefer to pass them as arguments.

    Can you save me the trouble of sorting through bad information from a search engine?

    (I've seen some info about using an ampersand, but it wasn't very clear)

    Are you saying that if I include the variables within the { } of the function that it will work?  I tried that earlier but it failed.

    If these variables will be used as reference to other functions, Is there a Best Practices path to proceed on?  Will wrapping the variables in a function of their own to be called inside of this function provide the desired result?

  8. While working with some code I wrote this and it works

    <?
    
    if(isset($_POST['submit'])) {
    $greeting = "Good morning";
    $late = "You are late";
    
    if($_POST['time'] > 0) {
    echo $greeting;
            }
    
    if($_POST['time'] > 5) {
    echo $late;
            }
      }
    
    ?>

    Then I decided to modify it into a function (which would be preferable for expanding the code's usefulness)

    That's when my problems began.

    What do I need to do so that the function works as well as the straight code?

    
    <?
    
    $greeting = "Good morning";
    $late = "You are late";
    
    function greet(){
    if($_POST['time'] > 0) {
    echo $greeting;
            }
    
    if($_POST['time'] > 5) {
    echo $late;
            }
        }
    
    if(isset($_POST['submit'])) {
    greet();
    }
    
    ?>

    I thought I'd ask the experts.

    Thanks.

  9. It seemed simple when I thought of it, but multiple variations are NOT producing the result I imagined.

    Essentially, I have a single table that I want centered on a webpage, with a second table to the right.

    <center><div>
      content 
    </div> </center>
    
    <div style="float: right;">
      content
     </div>

    I enclosed the tables in <div> tags but my results did not improve.

    I do not want two side by side tables that are centered. I am trying to have one centered table with a second to its right.

  10. What would be the car, in this instance? jQuery?

    The car has obvious advantages. (although there are far less deaths from buggy incidents per capita, so is the trade off worth it?)

    Not trying to be a smarty, but if you are referring to jQuery, I don't find it as straight forward as JS, so unless I'm missing some great advantage, I think I have enough troubles already. LOL

    As always, your insight and guidance are appreciated.

  11. If my form is submitted, but fails during PHP validation, then I want info that was already submitted to be available.

    <input type="text" name="username" value="<?php if(isset($_POST['username'];} { echo $username; } ?> >
      </div>

    This works fine and defines my goal.

    My troubles arose when I attempted a similar design with a drop-down menu.

    Making matters worse, that menu uses JavaScript.

    <script>
    document.write("<select  name='menu'>");
    for(i = 1; i < 20; i++)  {
    document.write("<option value=' "+i+"'> " + i + "</options>");
                   }
    document.write("</select>");
    </script>

    I've begun trying to add PHP into the <option> tag, but am not sure how (or if it's acceptable) to integrate the JS for the desired result.

    document.write("<option value=' "+i+"'
        <? if($_POST['menu'] == ?> +i+ <?        echo selected";?> 
                   > " + i + "</options>");

    I suppose I could swap the JS with PHP, but then I put unnecessary usage to the server.

    Best solution??

  12. OR perhaps I should take a different approach:

    I have a checkbox that controls a toggled effect on HTML background.

    var chosen = document.getElementById("XYZ4").checked;

     

    I'm considering adding a second checkbox that would have the same effect.

    Rather than hardcode both (and future) checkboxes, what would be the best way to retrieve an identifier so that it can be inserted as a variable and used to evaluate a condition?

  13. My very first entry on this topic was

    Quote

    I've tried an exhaustive array of variations with single quotes, double quotes, and + sign combinations, but seem to be missing the bullseye.

    I believe my initial effort was

    document.getElementById("+XYZ4+").checked;

    That's what necessitated the post.

    But I can try it again, I suppose.

  14. I just KNEW you were going to do that. LOL.

    However, I'm not sure it's accurate (as if you need something to keep you busy) because if the 19 is on Sunday, the holiday would be Monday. [minus 2 changed to plus 1 ??]

    Quote

    difference between a string value and a variable name

    Care to enlighten me?

  15. There's ALWAYS more code. But it's mostly HTML or unrelated.

    Essentially, I'm running through all the input tags and then separating those that are checkboxes.

    Then, I'm grabbing the ID of the checkboxes and using them [actually only one for now. ie:XYZ4] to "do stuff" depending on whether or not the box is checked.

    (I'd tell you what happens further down the line, but I haven't coded that far ahead yet. I was testing the waters as I progressed and stopped when I discovered this odd circumstance. However, my notion is to alter color or display a message if checked.)

    Again, it works when hardcoded and the number of checkboxes is minimal. But it would be nice to be able to have the code effective with each checkbox being evaluated through the 'for loop' (unless there's a better way to accomplish this).

  16. Signed into law yesterday to commemorate June 19, but recognized on the weekday closest to the 19th when 19 falls on the weekend.

    (This would be interesting to code. LOL)

    What kind of "observance" could there be if government workers weren't "entitled" to another day off from work (with pay)??

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