Jump to content

F1Fan

Members
  • Posts

    1,182
  • Joined

  • Last visited

Posts posted by F1Fan

  1. Hmm, that's a good start. The problem is that the DBs are PostgreSQL (critical), Oracle, AS400 (DB2), and MS SQL (which is the reason this isn't posted in a specific SQL board). PostgreSQL and Oracle use pgsql and oci8 MDB2 drivers, and the AS400 and MS SQL use odbc.

     

    I'm looking to see if there's an equivalent for each of those connections, but if you know and could tell me before I can search for it, that'd be cool!

  2. I have a site that connects to several databases. One is a critical connection, but the others are just for some non-essential reports. The problem is that when those secondary DBs are having issues, the entire site slows to a crawl.

     

    So, what I'd like to do is attempt to connect to all the DBs, but put a time limit on those that aren't essential. If the connect function for any of those DBs takes too long, kill that function and move on.

     

    Any ideas?

  3. jesirose is right, number_format is your best bet, but that will only answer the second question. It will round and display X number of decimals. As for displaying the zero to the left of the decimal, that you'll have to get creative. This should do it:

    $number = 0.3;
    list($leftOfDecimal, $rightOfDecimal) = explode('.', round($number, 3));
    if ($leftOfDecimal == 0){
      echo '.' . str_pad($rightOfDecimal, 3, STR_PAD_RIGHT);
    } else{
      echo number_format($number, 3, '.', ',');
    }

  4. Sorry, I had to change/remove quite a bit to make it generically usable, and in doing so forgot to change a few things and mention a few things.

     

    The getURLString() function will extract the variable string after the page. For example, if the URL was index.php#variableOne=something&variableTwo=somethingElse, this function will return variableOne=something&variableTwo=somethingElse. Using that, you should be able to extract those variables and their values.

     

    As for the checkForURLUpdates() function, and the reference to the checkForFeatureActionUpdates() function, that should have been like this:

       function checkForURLUpdates(){
          var currentLocation = window.location.href;
          if (previousURL != currentLocation){
             // do stuff
          }
          setTimeout("checkForURLUpdates()",1000);
       }

    Then, the checkForURLUpdates() function should be called when the page initially loads.

     

     

    Finally, I'll explain better how they all relate to each other.

     

    First, the checkForURLUpdates() function should be called on page load. That will set off the chain reaction that will catch the URL changes. You'll want to put whatever functions you want to occur when the URL has changed where I put "// do stuff." You'll have to write new custom functions here. You'll also use the getURLString() function to extract those variables and use your Ajax stuff to direct the user to the desired page.

     

    Second, whenever you change something with your Ajax calls, you'll need to update the URL with the new variables with this piece of code:

    top.location = "index.php#variableOne=something&variableTwo=somethingElse";
    previousURL = top.location;

     

     

    So, let's cover an example. Let's say the initial page is "index.php" and the user hasn't done anything. But, you have an Ajax call on page load, and that changes the URL to something like "index.php#stage=1." Then the user does something that makes another Ajax call. That changes the URL to "index.php#stage=2." One more time and the URL becomes "index.php#stage=3." Each time Ajax is called, you update both the actual URL and the global JavaScript variable "previousURL" to the new URL. Meanwhile, the checkForURLUpdates() function is constantly comparing the actual URL to that previousURL variable. That function isn't doing anything yet, because those two match. But, then the user clicks the back button. That changes the URL from "index.php#stage=3" to "index.php#stage=2," while the previousURL still equals "index.php#stage=3." This is where the checkForURLUpdates() function catches that difference and goes to work. At this point, your code will need to know what to do when the URL variable string is "stage=2" and act appropriately to give the user the page that matches stage 2.

     

    Does that help?

  5. I had this same problem, and I found a solution that works for Firefox and IE, but I have yet to find a Web-kit (Safari, Chrome) solution, mainly because it hasn't been a priority. If anyone can expand on my idea to work with Webkit browsers, I'm all ears.

     

     

    Here's how it works:

     

    Every time an Ajax call is made, JavaScript replaces the URL with a URL that is exactly the same, except for some variables that I am passing. The variables are ONLY passed to the RIGHT a #, which will not reload the browser. If you change anything to the left of the #, it will reload the whole page, which you obviously don't want. This is how that particular Ajax state can be "saved" to the URL. Then, each time this is changed by your JS function, you'll want to save that URL in a JS variable for use later.

     

    The second part of this is to then retrieve the URL state. You'll probably want to do this in two ways. The first way will be when the page loads. That way, if someone bookmarks the page with a # and a bunch of variables, they will get the desired page when they access that bookmark. The second way would be a JavaScript setInterval or setTimeout loop that periodically checks to see if the URL is different than the URL you previously saved in the JS variable from the first step. If it is different, that means the user either clicked the browser's back button, or they accessed that bookmark. I've found that a setInterval/setTimeout time of one second is the best compromise between there not being too much delay and also having very little effect on the user's CPU usage.

     

    Here's a brief example of the JS to replace the URL:

    top.location = "index.php#variableOne=something&variableTwo=somethingElse";
    previousURL = top.location;

    Here's a function to extract those variables:

    	function getURLString(){
    	var href = window.location.href;
    	var position = href.indexOf('#');
    	if (position==-1){
    		position = href.indexOf('?');
    	}
    	if (position>0){
    		position++;
    		return href.slice(position);
    	}
    	else{
    		return "";
    	}
    }

    Then parse them out, separating them out with the & character, then extracting the variable name and value with =.

    Finally, the function that looks for updates:

    	function checkForURLUpdates(){
    	var currentLocation = window.location.href;
    	if (previousURL != currentLocation){
    		// do stuff
    	}
    	setTimeout("checkForFeatureActionUpdates()",1000);
    }

     

     

    Hope this at least gives you ideas.

  6. Using Ajax would give you the most flexibility and would be best if you plan on pulling this data from a database, but if you will only ever have those two cities with those neighborhoods, just do it in JavaScript. Another option would be to write your JavaScript with PHP when the page initially loads. Here's a JS tutorial on adding and removing options from selects: http://www.javascriptkit.com/jsref/select.shtml

  7.     $("#changePass").click(function() {
            document.getElementById('changePass').disabled = true;
            document.getElementById('changePass').value = 'Loading...';
    
            $.ajax({
                type: "POST",
                url: "modules/forgotPassword/changePassword.php",
                data: {pass: $("#newPass").val(), confirmPass: $("#confirmPass").val(), email: $("#changePassEmail").val()},
                cache: false,
                success: function(html){
                    $("#changePassMessage").prepend(html);
                    $("#changePassMessage").slideDown("slow");
                    document.getElementById('content').value='';
                    document.getElementById('content').focus();
                    $("#changePassLoading").hide();
                    document.getElementById('changePass').disabled = false;
                    document.getElementById('changePass').value = 'Submit';
                }
            });
            return false;
        });

  8. So are you saying that you are trying to append to what ever is in the div, as long as it's not "Loading..."? If so, you're gonna have to something different. A few options:

    • Create logic that removes the last "Loading..." before appending with the requested data (not recommended, because you'll never know if that would remove any wanted data)
    • Create an additional place to put these messages and remove them whenever you want to, like maybe a jQuery dialog.
    • Or, the easiest, do the disable button thing that I suggested before, but in addition, change the button text temporarily to "Loading..." until it's done loading and then swap it back to whatever the button text (value) was before.

  9.                 $("#changePassMessage").prepend(html);

    This line is adding to the end of it (prepend). I'm not sure what the jQuery function is to just replace, but the standard JavaScript function would look like this:

    document.getElementById('changePassMessage').innerHTML = html;

    That would replace whatever is in there with your "html" variable.

  10. As far as having to click the button twice, are you positive? Have you tried clicking the button one time and waiting a long time? Maybe it is working the first time.

     

    I think a callback function is a good idea. Use it to empty all the input fields when the Ajax is complete. Also, it would be a good idea to do something that would notify the user that the script is running. Here's a REALLY simple example of something, but you could easily do something better. This will just give you the idea. Just put this at the beginning of your loadXMLDoc() JS function.

    document.getElementById('myDiv').innerHTML += '<br \><br \>Loading...';

  11. OK, I see two main problems. First, the "myDiv" div is being displayed within your while loop, rather than wrapping around it. If you viewed the HTML source of your page, you would see as many "myDiv" divs as you have rows. So, change those lines from this:

    while ($row = $result->fetch_assoc()) {
    
    
    
    
    
    
    
    
    
    //comment form vars
    
    
    
    $com_name=$row['com_name'];
    
    
    
    $com_email=$row['com_email'];
    
    
    
    $com_dis=$row['com_dis'];
    
    
    
    
    
    
    ?>
    
    
    
    
        <div id="myDiv">
    
    
    
    <strong><?php echo $com_name?></strong><br />
    
    
    
    <?php echo $com_dis?><br /><br />
        </div>
    
    <?php } ?>

    to this:

    <div id="myDiv">
    <?php
    while ($row = $result->fetch_assoc()) {
    
    //comment form vars
    $com_name=$row['com_name'];
    $com_email=$row['com_email'];
    $com_dis=$row['com_dis'];
    ?>
    
    <strong><?php echo $com_name?></strong><br />
    <?php echo $com_dis?><br /><br />
    
    <?php } ?>
    </div>

     

    The second problem, which is the bigger one, is that your insert_comment.php file isn't printing out the newly inserted row(s). You are printing out the comments when the page initially loads, but then that information is static. Calling your Ajax stuff isn't going to re-populate that stuff unless you tell it to. This may need to be cleaned up, but try this for your insert_comment.php file:

    require_once("functions.php");
    $connection = dbConnect(); //DB connect function
    if (isset($_GET["submit"])) {    
    $name = $connection->real_escape_string(strip_tags($_GET["com_name"]));
    $email = $connection->real_escape_string(strip_tags($_GET["com_email"]));
        $comment = $connection->real_escape_string(strip_tags($_GET["com_dis"]));
        $comment = nl2br($comment);
    $post_id = $connection->real_escape_string($_GET['post_id']);
    if (!$name || !$email || !$comment) {
    echo "Please go back and submit a new post.";
    exit;
    }
        $sql = "INSERT INTO comments
                     (com_name, com_email, com_dis, post_id, date)
              VALUES ('$name', '$email', '$comment', '$post_id', NOW())";
    $result = $connection->query($sql) or die(mysqli_error($connection));
    
    $sql = "SELECT * FROM comments WHERE post_id=$post_id ORDER BY date desc";
    $result = $connection->query($sql) or die(mysqli_error($connection));
    while ($row = $result->fetch_assoc()) {
    //comment form vars
    $com_name=$row['com_name'];
    $com_email=$row['com_email'];
    $com_dis=$row['com_dis'];
    ?>
    <strong><?php echo $com_name?></strong><br />
    <?php echo $com_dis?><br /><br />
    <?php }
    } else {
    echo "Access Denied";
    }

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