WordPress.org

Ready to get started?Download WordPress

Forums

jQuery to update database query (3 posts)

  1. johnwolf
    Member
    Posted 2 years 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

  2. webwarrior.wng
    Member
    Posted 1 year ago #

    Hi i want some help from you. My problem is that i want to update some field in wpdb onclick of the Social Share Image, below is the code:

    <img class="button_img" src="http://wisamtest.arrancr.co.uk/wp-content/plugins/buddypress-share-it/img/32px/Facebook.png" alt="Share on Facebook">

    I can access in jQuery by

    jQuery('.button_img').live('click', function(){
    			jQuery.ajax({
    				url: 'http://wisamtest.arrancr.co.uk/newpts.php',
    				data: "val1:value&lvaln:valn",
    				success: function(data) {
    					jQuery('.share-buttons').html(data);
    					}
    				});

    but i want to update the database fields.
    Thanks a lot in advance!

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your posted code may now have been permanently damaged/corrupted by the forum's parser.]

  3. johnwolf
    Member
    Posted 1 year ago #

    hey,
    well what do you do in your newpts.php
    database calls should be placed in this file... If it's related to wordpress table there is probably already a function for that. Be sure to call this in your file if it's outside WP.

    define('WP_USE_THEMES', false);
    require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php');

    they you can call global $wpdb and play with sql queries
    http://codex.wordpress.org/Class_Reference/wpdb

    hope this helps,

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags