Support » Plugins » jQuery to update database query

  • johnwolf


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

    	<th>Sous Jacent</th>
    $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>
    <?php }

    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=""></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var refreshId = setInterval(function() {
    }, 5000);
    $.ajaxSetup({ cache: false });

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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=”” alt=”Share on Facebook”>

    I can access in jQuery by

    jQuery('.button_img').live('click', function(){
    				url: '',
    				data: "val1:value&lvaln:valn",
    				success: function(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.]

    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

    hope this helps,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jQuery to update database query’ is closed to new replies.