我从表单数据插入到我的数据库中,在我创建一个带有FOR循环的文件后,我显示了我的表中的所有记录。我试图用页面上的数据刷新我的列表,而不是每当有新数据插入数据库时刷新。
main.php
<script type="text/javascript" >
function fetch(){
jQuery.ajax({
url: '/ajax.php',
success: function(data) {
jQuery(data).hide().prependTo("#list").slideDown("slow");
if(jQuery("#list li").length > 15){
jQuery('#list li:gt(14)').remove();
}
setTimeout("fetch()", 1000);
console.log(data);
}
});
}
</script>
PHP / HTML
<?php
require_once($_SERVER["DOCUMENT_ROOT"]."/wp-blog-header.php");
session_start();
wp_enqueue_style('il_style_mode');
wp_enqueue_style('il_admin_style_mode');
wp_enqueue_scripts('jquery');
global $_IL_ID;
global $_IL_LIMIT;
global $_IL_TOTAL;
global $wpdb;
$_IL_TABLE_NAME_INTERNAL = $wpdb->prefix . "il_internal_transfer";
$_SESSION['IL_COUNT_ADMIN'] = 1;
require_once ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer_tabs.php");
$_IL_START = 0;
$_IL_LIMIT = 10;
if( isset($_GET['paged']) ){
$_IL_ID = $_GET['paged'];
$_IL_START = ($_IL_ID-1) * $_IL_LIMIT;
}
$_IL_QUERY_INTERNAL = $wpdb->get_results( "SELECT * FROM $_IL_TABLE_NAME_INTERNAL ORDER BY il_id DESC LIMIT $_IL_START, $_IL_LIMIT");
$_IL_NUM_ROWS_INTERNAL_ALL = $wpdb->get_var( "SELECT COUNT(*) FROM $_IL_TABLE_NAME_INTERNAL");
echo '<span class="il_admin_main_title">';
echo '<span>';
echo '<h2>Internal Transfers</h2>';
echo '</span>';
echo '<span>';
require_once ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer_sub_tabs.php");
echo '</span>';
echo '</span>';
echo '<span class="il_admin_transactions_block" id="il_admin_transactions_block">';
if( $_IL_NUM_ROWS_INTERNAL_ALL < 1 ){
include ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_include/il_messages/il_internal_transfer_sorry.php");
}else{
require_once ($_SERVER["DOCUMENT_ROOT"]."/ajax.php");
}
echo '</span>';
if(isset($_POST['il_status_update'])){
$wpdb->update(
$_IL_TABLE_NAME_INTERNAL,
array(
'il_status' => $_POST['il_status_new'],
),
array( 'il_id' => $_POST['il_transaction_id'] ),
array(
'%s',
),
array( '%s' )
);
};
if(isset($_POST['il_delete'])){
$wpdb->delete( $_IL_TABLE_NAME_INTERNAL, array( 'il_id' => $_POST['il_transaction_id'] ), array( '%d' ) );
};
$_IL_ROWS_COUNT = mysql_num_rows(mysql_query("select * from $_IL_TABLE_NAME_INTERNAL"));
$_IL_TOTAL = ceil( $_IL_ROWS_COUNT / $_IL_LIMIT );
if($_IL_LIMIT < $_IL_ROWS_COUNT){
echo '<span class="il_pagination_block_admin">';
if( $_IL_ID > 1 )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".($_IL_ID-1)."' class='il_pagination_prev'><span class='il_pagination_prev_icon'></span></a>";
}
echo "<ul class='il_pagination'>";
for( $i = 1; $i <= $_IL_TOTAL; $i++ )
{
if( $i == $_IL_ID ) { echo "<li class='il_pagination_current'>".$i."</li>"; }
else { echo "<li><a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
if( $_IL_ID != $_IL_TOTAL )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".( $_IL_ID + 1 )."' class='il_pagination_next'><span class='il_pagination_next_icon'></span></a>";
}
echo "</span>";
}else{
}
?>
ajax.php
<?php
require_once($_SERVER["DOCUMENT_ROOT"]."/wp-blog-header.php");
wp_enqueue_style('il_style_mode');
wp_enqueue_style('il_admin_style_mode');
wp_enqueue_scripts('jquery');
global $wpdb;
$_IL_TABLE_NAME_INTERNAL = $wpdb->prefix . "il_internal_transfer";
$_IL_QUERY_INTERNAL = $wpdb->get_results( "SELECT * FROM $_IL_TABLE_NAME_INTERNAL ORDER BY il_id DESC LIMIT $_IL_START, $_IL_LIMIT");
echo '<ul id="list">';
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA)
{
?>
<li>
<span class="il_admin_transactions_block_raw_block">
<form method="post">
<input type='hidden' name='il_transaction_id' value="<?php echo $_IL_RESULT_DATA->il_id ?>" />
<span class="il_admin_transactions_block_raw">
<span class="il_admin_transactions_block_raw_count"><?php echo $_SESSION['IL_COUNT_ADMIN'] ?></span>
<span class="il_admin_internal_block_raw_full_name">
<?php echo $_IL_RESULT_DATA->il_name ?>
</span>
<span class="il_admin_internal_block_raw_from_to">
<span><?php echo $_IL_RESULT_DATA->il_from_mt4 ?></span> <?php echo $_IL_RESULT_DATA->il_from_mt4_currency ?>
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_gray_left_icon.png" class="il_arrow_between" />
<span><?php echo $_IL_RESULT_DATA->il_to_mt4 ?></span> <?php echo $_IL_RESULT_DATA->il_to_mt4_currency ?>
</span>
<span class="il_admin_internal_block_raw_email"><?php echo $_IL_RESULT_DATA->il_email ?></span>
<span class="il_admin_internal_block_raw_date"><?php echo $_IL_RESULT_DATA->il_date ?></span>
</span>
<span class="il_admin_transactions_block_raw_extras">
<?php if( $_IL_RESULT_DATA->il_comments === NULL || empty($_IL_RESULT_DATA->il_comments) ){ ?>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_comment">
<span>Comment:</span>
<span><?php echo $_IL_RESULT_DATA->il_comments ?></span>
</span>
<?php } ?>
<?php if( $_IL_RESULT_DATA->il_status == 'approved' ){ ?>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_extras_status_icon">
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_green_status_<?php echo $_IL_RESULT_DATA->il_status ?>_icon.gif" alt="Processing" title="Processing"/>
</span>
<?php } ?>
<span class="il_admin_transactions_block_raw_extras_ip">
The transaction was done from this ip <?php echo $_IL_RESULT_DATA->il_user_ip ?>
</span>
<span class="il_admin_transactions_block_raw_extras_ip_select">
<?php if( $_IL_RESULT_DATA->il_status == 'approved' ){ ?>
<span class="il_admin_transactions_block_raw_extras_status_<?php echo $_IL_RESULT_DATA->il_status ?>"><?php echo $_IL_RESULT_DATA->il_status ?></span>
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_green_status_<?php echo $_IL_RESULT_DATA->il_status ?>_icon.gif" alt="Processing" title="Processing" width="20"/>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_extras_update">
<select name="il_status_new">
<option>approved</option>
<option>waiting</option>
<option>rejected</option>
</select>
</span>
<span class="il_admin_transactions_block_raw_extras_update_button">
<input type="submit" name="il_status_update" value="update status" />
<input type="submit" name="il_delete" value="delete" class="il_admin_transactions_delete_button" />
</span>
<?php } ?>
</span>
</span>
<span class="il_clear"></span>
</form>
</span>
</li>
<?php
$_SESSION['IL_COUNT_ADMIN']++;
}
echo '</ul>';
实际上我正在尝试的是每次在我的表中插入新数据时我想使用来自ajax.php的循环在我的列表中自动显示它们