Forums

jQuery to update database query (1 post)

  1. johnwolf
    Member
    Posted 4 months ago #

    Hello everyone. I posted about this on many php forum and noone responded :( hoping someone can direct me here.

    So I have some PHP to extract some data from mysql. It works fine..

    <table>
    	<th>Statut</th>
    	<th>Sous Jacent</th>
    	<th>Sens</th>
    	<th>Entrée</th>
    	<th>Stop</th>
    	<th>Objectifs</th>
    <?php
    
    $datab_name = $wpdb->prefix . "trades";
    $alltrades = $wpdb->get_results(
    	"
    	SELECT *
    	FROM $datab_name
    	WHERE status = 'En cours'
    		AND tk_live = 0
    	OR status = 'En attente'
    		AND tk_live = 0
    	"
    );
    
    foreach ( $alltrades as $alltrades )
    {	$sens = $alltrades->sens;
    	$entree = $alltrades->entree;
    	$sortie = $alltrades->sortie;
    	?> <tr>
    	<td><?php echo $alltrades->status;?></td>
    	<td><?php echo $alltrades->sous_jacent;?></td>
    	<td><?php echo $alltrades->sens;?></td>
    	<td><?php echo $entree;?><br><?php echo $alltrades->date_entree;?></td>
    	<td><?php echo $alltrades->stop;?></td>
    	<td><?php echo $alltrades->objectif1;?>
    		<br><?php echo $alltrades->objectif2;?>
    		<br><?php echo $alltrades->objectif3;?></td>
    	</tr>
    <?php }
    
     ?>
    </table>

    Then I wanted this table to be updated automatically without a page refresh, so used a script that will refresh the div, the script loads my table (since the headings are loaded) but does not seem to execute my php script (query the database.)

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function() {
    
    $("#loaddiv").fadeOut("fast").load("/tk/wp-content/themes/twentyeleven/trades-brief.php").fadeIn("slow");
    
    var refreshId = setInterval(function() {
    $("#loaddiv").fadeOut("fast").load("/tk/wp-content/themes/twentyeleven/trades-brief.php").fadeIn("slow");
    }, 5000);
    
    $.ajaxSetup({ cache: false });
    
    });
    
    </script>

    Any directions on how I could implement this would be greatly appreciated. Regards
    john

Reply

You must log in to post.

About this Topic

Tags