Results 1 to 2 of 2

Thread: Jquery/AJAX/PHP and Arrays OH MY!

  1. #1
    Join Date
    Feb 2010
    Posts
    29

    Red face Jquery/AJAX/PHP and Arrays OH MY!

    So, I'm trying to learn Jquery/Axaj using an array to execute and update code on different elements within a single function.

    Below, I'm trying to update the DIVs with the number of people logged into the site, and the total currency in circulation. The script will update every few seconds.

    Can anyone help me correct my syntax or at least tell me what I'm doing wrong here?

    HTML Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="../jquery.js"></script>
    
    <script type="text/javascript">
    function updateStats(stat)
    {
    	var stat = ["online","money"];
    	
    	var url = "online.php";
    	
    	$.each(stat,function(stat){
    		
    	$.post(url,{stat: stat} , function(data) {
    		
    		$("#" + this).html(data);		
    	})
    	
    	})	
    } 
    
    setInterval('updateStats("updateStats")', 2000);
    </script>
    
    
    <body onLoad="updateStats(stats);">
    
    <div id="online"></div>
    <div id="money"></div>
    </body>
    </html>
    ----------------
    PHP Code:
    <?php

    if($_POST['stats']=='online')
    {
        
    $result$mysqli->query("SELECT loggedin FROM accounts WHERE loggedin !=0");
        echo 
    $result->num_rows;    


    elseif(
    $_POST['stats'] == 'money')
    {
    $result $mysqli->query("SELECT sum(money) AS totalMoney FROM users");
    $getData $result->fetch_assoc();

    echo 
    number_format($getData['totalMoney']);

    }

    $mysqli->close();

    ?>

  2. #2
    Join Date
    Apr 2012
    Posts
    8
    this code connect with database ?

Similar Threads

  1. AJAX using JQUERY
    By wotupduck in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Mar 2011, 06:01 PM
  2. Need to emulate Java style Byte Arrays in php
    By Mordax in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 02 Oct 2010, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •