i am inserting from a form data into my database, after i create a file with a FOR loop that i display all the records from my table. I am trying to refresh my list with data on a page without refresh every time when there was inserted new data into database.
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>';
actually what i am trying is every time when new data will be inserted in my table i want to display them automatically in my list using the loop from ajax.php
Related
This is from an unsupported WordPress plugin that I'm trying to revive. I'm getting an error in the following code which states
Fatal Error class WP_Widget not found on Line 7
It works with PHP 5.3.3 but not on 5.6 or any version of PHP 7. Any suggestions would be appreciated.
<?php
/**
*
* Widget Class
*/
class Twitter_Like_Box_Widget extends WP_Widget
{
var $_options;
function __construct( ) {
global $tlb;
$this->wpb_prefix = $tlb->get_domain();
$widget_ops = array( 'classname' => 'tlb_widget', 'description' => ' Display your Twitter followers along with a follow me button' ); // Widget Settings
$control_ops = array( 'id_base' => 'tlb_widget' ); // Widget Control Settings
parent::__construct( 'tlb_widget', 'Twitter Like Box', $widget_ops, $control_ops );
$this->_options = $tlb->getOptions();
}
//Function to init the widget values and call the display widget function
function widget($args,$instance)
{
$title = apply_filters('widget_title', $instance['title']); // the widget title
$username = $instance['username']; // the widget title
$total_number = $instance['total_number']; // the number of followers to show
$show_followers = $instance['show_followers']; // show followers or users i follow
$link_followers = $instance['link_followers']; // link followers to profile
$width = $instance['width']; // link followers to profile
$widget = array ( 'username' => $username ,'total' => $total_number , 'show_followers' => $show_followers ,'link_followers'=> $link_followers, 'width' => $width, 'options' => $this->_options);
echo $args['before_widget'];
if ( $title )
echo $args['before_title'] . $title . $args['after_title'];
$this->display_widget($widget);
echo $args['after_widget'];
}
//function that display the widget form
function form($instance)
{
global $tlb;
$defaults = array( 'total_number' => 10, 'show_followers' => 'followers','link_followers'=> 'on','title' => 'My Followers', 'username' => 'chifliiiii');
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<?php if( $tlb->error != '' && defined('DOING_AJAX')):?>
<div class="error">
<p><?php echo sprintf(__('Check you OAuth settings, there is a problem with the connection.',$this->wpb_prefix),admin_url('options-general.php?page=twitter-like-box-reloaded'));?></p>
</div>
<?php endif;?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:',$this->wpb_prefix);?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>'" type="text" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('username'); ?>"><?php _e('Username (without #):',$this->wpb_prefix);?></label>
<input class="widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>'" type="text" value="<?php echo $instance['username']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('show_thumbs'); ?>"><?php _e('Show Followers or people you follow?',$this->wpb_prefix);?></label>
</p>
<ul>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'followers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="followers"/> <?php _e('Followers',$this->wpb_prefix);?>
</li>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'nofollowers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="nofollowers" /> <?php _e('People I follow',$this->wpb_prefix);?>
</li>
</ul>
<p>
<label for="<?php echo $this->get_field_id('total_number'); ?>"><?php _e('How many you want to show?',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('total_number'); ?>" name="<?php echo $this->get_field_name('total_number'); ?>" type="text" value="<?php echo $instance['total_number']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link_followers'); ?>"><?php _e('Link followers to their profiles?',$this->wpb_prefix); ?></label>
<input type="checkbox" class="checkbox" <?php checked( $instance['link_followers'], 'on' ); ?> id="<?php echo $this->get_field_id('link_followers'); ?>" name="<?php echo $this->get_field_name('link_followers'); ?>" value="on" />
</p>
<p>
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Widget width:',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width') ; ?>'" type="text" value="<?php echo isset($instance['width']) ? $instance['width'] : '100%'; ?>" />
</p>
<p>
<?php _e('More settings',$this->wpb_prefix);?>
</p>
<?php
}
//function that save the widget
function update($new_instance, $old_instance)
{
$instance['title'] = strip_tags($new_instance['title']);
$instance['username'] = strip_tags( $new_instance['username'] )== '' ? 'chifliiiii' : strip_tags( $new_instance['username'] );
$instance['total_number'] = strip_tags($new_instance['total_number']);
$instance['show_followers'] = $new_instance['show_followers'];
$instance['link_followers'] = $new_instance['link_followers'];
$instance['width'] = $new_instance['width'];
//Delete transient in case exist
$key = 'tlb_widgets_' . $instance['username'];
delete_transient($key);
return $instance;
}
//Finally thevfunction that create the widget
static function get_tlb_widget($widget)
{
global $tlb,$you;
$wpb_prefix = $tlb->get_domain();
$twitter = self::fetch_twitter_followers($widget);
ob_start();
if( !empty($you['error']) && '32' == $you['code']) {
echo $you['error'];
}
else
{
?>
<style type="text/css">
<?php echo $widget['options']['custom_css'];?>
</style>
<div id="tlb_container" style="width: <?php echo isset($widget['width']) ? $widget['width'] : 'auto';?>">
<?php if(isset($twitter['error']) ) :?>
<?php echo $twitter['error'];?>
<?php else : ?>
<div>
<div id="tlb_profile_img">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<img src="<?php echo $twitter['profile_image_url'];?>" width="44" height="44" align="left" alt="<?php echo $widget['username'];?>">
</a>
</div>
<div id="tlb_name">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<?php echo $widget['username'];?><span> <?php _e('on Twitter',$wpb_prefix);?></span>
</a>
</div>
<div id="tlb_follow">
<?php _e('Follow #',$wpb_prefix);?><?php echo $widget['username'];?>
</div>
</div><br>
<div style="padding:0; color:#637746;">
<div id="tlb_follow_total">
<?php
if ( $widget['show_followers'] == 'followers')
{
echo $twitter['followers_count'].' '.__('people follow',$wpb_prefix).' <strong>'. $widget['username'].'</strong>';
}
else
{
echo __('You follow ',$wpb_prefix). $twitter['friends_count'].__(' users',$wpb_prefix);
}
?>
</div>
<?php for($i=0; $i < $widget['total']; $i++) :?>
<span class="tlb_user_item">
<?php if($widget['link_followers'] == 'on' ): ?>
<a target="_blank" href="http://twitter.com/<?php echo $twitter['followers'][$i]['screen_name'];?>" title="<?php echo $twitter['followers'][$i]['screen_name'];?>" rel="nofollow">
<?php endif;?>
<img src="<?php echo $twitter['followers'][$i]['profile_image_url'];?>" width="48" height="48" alt="<?php echo $twitter['followers'][$i]['screen_name'];?>">
<span><?php echo substr($twitter['followers'][$i]['screen_name'], 0, 8);?></span>
<?php if($widget['link_followers'] == 'on' ): ?>
</a>
<?php endif;?>
</span>
<?php endfor;?>
<br style="clear:both">
</div>
<?php if ( $widget['options']['credits'] == 'true' ) echo '<div style="font-size:9px;text-align:right;">Widget By Timersys</div>';?>
<?php endif;//twitter error ?>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<?php
}
$widget_code = ob_get_contents();
ob_end_clean();
return $widget_code;
}
/**
* Display widget
*/
static function display_widget($options){
echo Twitter_Like_Box_Widget::get_tlb_widget($options);
}
static function fetch_twitter_followers($options)
{
global $tlb,$you;
$cache_time = $tlb->_options['cache-time'];
$id = isset($options['id']) ? $options['id'] : 'widgets';
$key = 'tlb_'.$id.'_' . $options['username'];
// Let's see if we have a cached version
$followers = get_transient($key);
if ($followers !== false)
return $followers;
else
{
$tlb->connect();
$response = $tlb->connection->get("users/lookup", array('screen_name' => $options['username']));
if (Twitter_Like_Box_Widget::is_twitter_error($response))
{
// In case Twitter is down we return the last successful count
return get_option($key);
}
else
{
$json = $response;
#$you['name'] = $json[0]->name;
#$you['screen_name'] = $json[0]->screen_name;
#$you['followers_count'] = $json[0]->followers_count;
#$you['profile_image_url'] = $json[0]->profile_image_url;
#$you['friends_count'] = $json[0]->friends_count;
if ( $options['show_followers'] == 'followers' )
{
$fans = $tlb->connection->get('followers/ids',array('screen_name' => $options['username']));
}
else
{
$fans = $tlb->connection->get('friends/ids',array('screen_name' => $options['username']));
}
if (!Twitter_Like_Box_Widget::is_twitter_error($fans))
{
if ($options['total'] > 90 )
{
$fans_ids = array_chunk($fans->ids, 90);
$fans = array();
foreach ( $fans_ids as $ids_a )
{
$fans_ids = (string)implode( ',', $ids_a );
#$result = $tlb->connection->get('users/lookup',array('user_id' => $fans_ids ));
#$fans = array_merge($fans , $result );
}
}
else
{
$fans_ids = (string)implode( ',', array_slice($fans->ids, 0, $options['total']) );
#$fans = $tlb->connection->get('users/lookup',array('user_id' =>$fans_ids));
}
}
if( !Twitter_Like_Box_Widget::is_twitter_error($fans) && isset($fans[0]->screen_name) )
{
$followers = array();
for($i=0; $i < $options['total']; $i++)
{
$followers[$i]['screen_name'] = (string)$fans[$i]->screen_name;
$followers[$i]['profile_image_url'] = (string)$fans[$i]->profile_image_url;
}
$you['followers'] = $followers;
// Store the result in a transient, expires after 1 hour
// Also store it as the last successful using update_option
set_transient($key, $you, 60*60* $cache_time);
update_option($key, $you);
}
return $you;
}
}
}
static function is_twitter_error($response){
global $you,$tlb;
if(is_object($response) && isset($response->errors) )
{
$you['error'] = 'Error code: '. $response->errors[0]->code .'<br>Error message: '.$response->errors[0]->message;
$you['code'] = $response->errors[0]->code;
$tlb->log_error($you['error']);
return true;
}
if(is_object($response) && isset($response->ids) && empty($response->ids))
{
$you['error'] = '<br>Error message: You got no users to show. check if you have followers';
$tlb->log_error($you['error']);
return true;
}
return false;
}
} //end of class
Wordpress have ABSPATH variable defined in wp-config.php file, which contains the project's root path. Now we can include any file of wordpress codebase. eg.
require_once ABSPATH.'wp-includes/class-wp-widget.php';
I don't know the reason for the error, propably something with autoloading, but you can solve it if you include the file for the WP_Widget class in the first line.
require_once get_home_path()."wp-includes/class-wp-widget.php";
I have two WordPress installs, one is to be used as an intranet and the other is public. I need to pull in the data for a custom post type from the public site to be shown on the intranet, essentially so the admin doesn't need to enter the same data on each site.
So, far I've got this:
$wpdb = new wpdb(*CONNECTION DETAILS*);
$careers = $wpdb->get_results(
'SELECT *
FROM wp_posts
WHERE post_type = "career-post"'
);
if (!empty($careers)) {
echo '<ul id="careers-list">';
foreach ($careers as $career) {
echo '<li class="career">';
echo '<a class="wrap" href="http://domainname.com/career/'.$career->post_name.'" target="_blank">';
echo '<h2>'.$career->post_title.'</h2>';
echo get_field('career_duration') ? '<p class="duration">('.get_field('career_duration').')</p>' : '<p class="duration">(permanent)</p>';
echo '<h3>'.get_field('career_area').'</h3>';
echo '<p class="description">'.get_field('career_short_description').'</p>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
Which is pulling in the slug and title as expected, but as the ACF data is stored in a different table, I am not sure how to a) access that data and b) link it to the correct post.
Fetch ACF fields for a custom post type
<?php
$wpdb = new wpdb(*CONNECTION DETAILS*);
$careers = $wpdb->get_results(
'SELECT *
FROM wp_posts
WHERE post_type = "career-post"'
);
if (!empty($careers)) {
?>
<ul id="careers-list">
<?php
foreach ($careers as $career) {
$career_duration = get_field('career_duration', $career->ID);
$career_area = get_field('career_area', $career->ID);
$career_short_description = get_field('career_short_description', $career->ID);
?>
<li class="career">
<a href="<?php echo get_permalink($career->ID); ?>" target="_blank">
<h2><?php echo get_the_title( $career->ID ); ?></h2>
<?php
if($career_duration!="")
{
?>
<p class="duration"><?php echo $career_duration;?></p>
<?php
}
else
{
?>
<p class="duration">permanent</p>
<?php
}
?>
<h3><?php echo $career_area;?></h3>
<p class="description"><?php echo $career_short_description;?></p>
</a>
</li>
<?php
}
?>
</ul>
<?php
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
?>
OR
<?php
$career_post_type = 'career-post';
$career_post_args=array(
'type' => $career_post_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => -1,
'orderby' => 'name',
'order' => 'ASC',
);
$career_post_my_query = null;
$career_post_my_query = new WP_Query($career_post_args);
if( $career_post_my_query->have_posts() )
{
?>
<ul id="careers-list">
<?php
while ($career_post_my_query->have_posts()) : $career_post_my_query->the_post();
$career_duration = get_field('career_duration', $post->ID);
$career_area = get_field('career_area', $post->ID);
$career_short_description = get_field('career_short_description', $post->ID);
?>
<li class="career">
<a href="<?php echo get_permalink($post->ID); ?>" target="_blank">
<h2><?php echo get_the_title( $post->ID ); ?></h2>
<?php
if($career_duration!="")
{
?>
<p class="duration"><?php echo $career_duration;?></p>
<?php
}
else
{
?>
<p class="duration">permanent</p>
<?php
}
?>
<h3><?php echo $career_area;?></h3>
<p class="description"><?php echo $career_short_description;?></p>
</a>
</li>
<?php
endwhile;
?>
</ul>
<?php
}
else {
echo '<h2>Sorry, no vacancies are currently listed.</h2>';
}
wp_reset_query($career_post_my_query);
?>
Shital, I don't see how your second solution would work as it's not referencing the external DB?
I've tried the following (similar to your first solution) and it doesn't return anything for the ACF fields either:
foreach ($careers as $career) {
$ID = $career->ID;
$slug = $career->post_name;
$title = $career->post_title;
$duration = get_field('career_duration', $ID);
$area = get_field('career_area', $ID);
$description = get_field('career_short_description', $ID);
echo '<li class="career">';
echo '<a class="wrap" href="http://domainname.com/career/'.$slug.'" target="_blank">';
echo '<h2>'.$title.'</h2>';
echo $duration ? '<p class="duration">('.$duration.')</p>' : '<p class="duration">(permanent)</p>';
echo '<h3>'.$area.'</h3>';
echo '<p class="description">'.$description.'</p>';
echo '</a>';
echo '</li>';
}
i am trying to make an ajax call to my database and refresh my list that i display from database. Actually what i need is, i have a table with data and i display them using php, now i want to update my list on the page without refresh anytime when in my table is inserting a new row.
sample code
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA){
echo $_IL_RESULT_DATA->il_name; //display all the name from my table
}
For example:
In my table i have 5 names and you can see them on the page, now somene subit a form and i insert the sixth name in my table, and i want to update my list with the sith name as real time with no refreshing.
I will appreciate any help.
My complete code
<?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">';
echo '<ul id="list">';
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{
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA)
{
?>
<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>
<?php
$_SESSION['IL_COUNT_ADMIN']++;
}
}
echo '</ul>';
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{
}
?>
<script>
jQuery( document ).ready(function($) {
function fetch(){
$.ajax({
url: '/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer.php',
success: function(data) {
$(data).hide().prependTo("#list").slideDown("slow");
if($("#list li").length > 15){
$('#list li:gt(14)').remove();
}
setTimeout("fetch()", 5000);
}
});
}
});
</script>
Use this JS code for live updating your result. Code will append new result at the top.
JS CODE
function fetch(){
$.ajax({
url: 'PATH-TO_FILE',
success: function(data) {
$(data).hide().prependTo("#list").slideDown("slow");
if($("#list li").length > 15){
$('#list li:gt(14)').remove();
}
setTimeout("fetch()", 5000);
}
});
}
HTML CODE
<ul id="list">
<?php
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA){
echo $_IL_RESULT_DATA->il_name; //display all the name from my table
}
?>
</ul>
I'm a noob running a project theme Wordpress website. There is a widget that shows a "Browse by Category" list in columns.
The widget shows the post count in brackets next to the category heading. I want to remove that.
Any help would be greatly appreciated.
This is the code for the widget:
add_action('widgets_init', 'register_browse_by_category_widget');
function register_browse_by_category_widget() {
register_widget('ProjectTheme_browse_by_category');
}
class ProjectTheme_browse_by_category extends WP_Widget {
function ProjectTheme_browse_by_category() {
$widget_ops = array( 'classname' => 'browse-by-category', 'description' => 'Show all categories and browse by category' );
$control_ops = array( 'width' => 200, 'height' => 250, 'id_base' => 'browse-by-category' );
$this->WP_Widget( 'browse-by-category', 'ProjectTheme - Browse by Category', $widget_ops, $control_ops );
}
function widget($args, $instance) {
extract($args);
echo $before_widget;
if ($instance['title']) echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title;
$loc_per_row = $instance['loc_per_row'];
$widget_id = $args['widget_id'];
$nr_rows = $instance['nr_rows'];
$only_these = $instance['only_these'];
$only_parents = $instance['only_parents'];
if($only_parents == "on") $only_parents = true;
else $only_parents = false;
$nr = 4;
if(!empty($loc_per_row)) $nr = $loc_per_row;
echo '<style>#'.$widget_id.' #location-stuff li>ul { width: '.(round(100/$nr)-0.5).'%}</style>';
if($nr_rows > 0) $jk = "&number=".($nr_rows * $loc_per_row);
$terms_k = get_terms("project_cat","parent=0&hide_empty=0");
$terms = get_terms("project_cat","parent=0&hide_empty=0".$jk);
//$term = get_term( $term_id, $taxonomy );
if($only_these == "1")
{
$terms = array();
foreach($terms_k as $trm)
{
if($instance['term_' . $trm->term_id] == $trm->term_id)
array_push($terms, $trm);
}
}
//-----------------------------
if(count($terms) < count($terms_k)) $disp_btn = 1;
else $disp_btn = 0;
$count = count($terms); $i = 0;
if ( $count > 0 ){
echo "<ul id='location-stuff'>";
foreach ( $terms as $term ) {
if($i%$nr == 0) echo "<li>";
$total_ads = 0;
$terms2 = '';
$terms2 = get_terms("project_cat","parent=".$term->term_id."&hide_empty=0");
$mese = '';
$mese .= '<ul>';
$mese .= "<img src=\"".get_bloginfo('template_url')."/images/posted.png\" width=\"20\" height=\"20\" />
<h3><a class='parent_taxe' rel='taxe_project_cat_".$term->term_id."' href='".get_term_link($term->slug,"project_cat")."'>" . $term->name;
//."</a></h3>";
$total_ads = ProjectTheme_get_custom_taxonomy_count('project',$term->slug);
$mese2 = '';
if($terms2 && $only_parents == false)
{
foreach ( $terms2 as $term2 )
{
$tt = ProjectTheme_get_custom_taxonomy_count('project',$term2->slug);
$total_ads += $tt;
//$mese2 .= "<li><a href='".get_term_link($term2->slug,"project_cat")."'>" . $term2->name." (".$tt.")</a></li>";
$mese2 .= "<li><a href='".get_term_link($term2->slug,"project_cat")."'>" . $term2->name." </a></li>";
}
}
echo $mese."(".$total_ads.")</a></h3>";
echo '<ul id="_project_cat_'.$term->term_id.'">'.$mese2."</ul>";
echo '</ul>';
if(($i+1) % $nr == 0) echo "</li>";
$i++;
}
//if(($i+1) % $nr != 0) echo "</li>";
echo "</ul>";
}
if($disp_btn == 1)
{
echo '<br/><b>'.__('See More Categories','ProjectTheme').'</b>';
}
echo $after_widget;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) { ?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?>:</label>
<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>"
value="<?php echo esc_attr( $instance['title'] ); ?>" style="width:95%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id('only_parents'); ?>"><?php _e('Only show parent categories'); ?>:</label>
<input type="checkbox" id="<?php echo $this->get_field_id('only_parents'); ?>" name="<?php echo $this->get_field_name('only_parents'); ?>"
<?php echo (esc_attr( $instance['only_parents'] ) == "on" ? "checked='checked'" : ""); ?> />
</p>
<p>
<label for="<?php echo $this->get_field_id('loc_per_row'); ?>"><?php _e('Number of Columns'); ?>:</label>
<input type="text" id="<?php echo $this->get_field_id('loc_per_row'); ?>" name="<?php echo $this->get_field_name('loc_per_row'); ?>"
value="<?php echo esc_attr( $instance['loc_per_row'] ); ?>" style="width:20%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Number of Rows'); ?>:</label>
<input type="text" id="<?php echo $this->get_field_id('nr_rows'); ?>" name="<?php echo $this->get_field_name('nr_rows'); ?>"
value="<?php echo esc_attr( $instance['nr_rows'] ); ?>" style="width:20%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Only show categories below'); ?>:</label>
<?php echo '<input type="checkbox" name="'.$this->get_field_name('only_these').'" value="1" '.(
$instance['only_these'] == "1" ? ' checked="checked" ' : "" ).' /> '; ?>
</p>
<p>
<label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Categories to show'); ?>:</label>
<div style=" width:220px;
height:180px;
background-color:#ffffff;
overflow:auto;border:1px solid #ccc">
<?php
$terms = get_terms("project_cat","parent=0&hide_empty=0");
foreach ( $terms as $term ) {
echo '<input type="checkbox" name="'.$this->get_field_name('term_'.$term->term_id).'" value="'.$term->term_id.'" '.(
$instance['term_'.$term->term_id] == $term->term_id ? ' checked="checked" ' : "" ).' /> ';
echo $term->name.'<br/>';
}
?>
</div>
</p>
<?php
}
}
?>
this is the part of code that writes the number of posts by category ...
change this
echo $mese."(".$total_ads.")</a>
with
echo $mese."</a>";
I'm coding a staff panel but I'm stuck I've added a menu (navigation) but I'm stuck on how to go about opening it when clicked and closing it when clicked if open.
Here is the code i have so far;
<ul id="menu" class="nav">
<?php
$url = $_GET['url'] ? $core->clean($_GET['url']) : 'core.home';
$query3 = $db->query("SELECT * FROM menu WHERE url = '{$url}'");
$array3 = $db->assoc($query3);
if (!$array3['usergroup']) {
$array3['usergroup'] = "invalid";
}
$query = $db->query("SELECT * FROM usergroups ORDER BY weight ASC");
while ($array = $db->assoc($query)) {
if (in_array($array['id'], $user->data['uGroupArray'])) {
?>
<div class="menustyle" onclick="Radi.menuToggle('<?php echo $array['id']; ?>');">
<div class="menutext"><?php echo $array['name']; ?></div>
</div>
<ul>
<li class="menuitems"<?php if ($array['id'] != $array3['usergroup']) { ?> onclick="Radi.menuToggle('<?php echo $array['id']; ?>');" style="display: none;"<?php } ?> id="mitems_<?php echo $array['id']; ?>">
<?php
$query2 = $db->query("SELECT * FROM menu WHERE usergroup = '{$array['id']}' AND visible = '1' ORDER BY weight ASC");
$i = "a";
while ($array2 = $db->assoc($query2)) {
?>
<li>
<?php echo $array2['text']; ?>
</li>
<?php
$i++;
if ($i == "c") {
$i = "a";
}
}
?>
</ul>
</li>
<?php
}
}
?>
</li>
</ul>
</div>
And this is the defualt code when you download radipanel;
<div style="float: left; width: 200px;">
<?php
$url = $_GET['url'] ? $core->clean($_GET['url']) : 'core.home';
$query3 = $db->query("SELECT * FROM menu WHERE url = '{$url}'");
$array3 = $db->assoc($query3);
if (!$array3['usergroup']) {
$array3['usergroup'] = "invalid";
}
$query = $db->query("SELECT * FROM usergroups ORDER BY weight ASC");
while ($array = $db->assoc($query)) {
if (in_array($array['id'], $user->data['uGroupArray'])) {
?>
<div class="box">
<div class="square menu" style="background: #<?php echo $array['colour']; ?>;" onclick="Radi.menuToggle('<?php echo $array['id']; ?>');">
<img id="menutoggle_<?php echo $array['id']; ?>" class="menutoggle" src="_img/<?php echo ( $array['id'] != $array3['usergroup'] ) ? 'plus' : 'minus'; ?>_white.png" alt="Toggle" align="right" />
<strong><?php echo $array['name']; ?></strong>
</div>
<div class="menuitems"<?php if ($array['id'] != $array3['usergroup']) { ?> style="display: none;"<?php } ?> id="mitems_<?php echo $array['id']; ?>">
<?php
$query2 = $db->query("SELECT * FROM menu WHERE usergroup = '{$array['id']}' ORDER BY weight ASC");
$i = "a";
while ($array2 = $db->assoc($query2)) {
?>
<a href="<?php echo $array2['url']; ?>" class="<?php echo $i; ?>">
<?php echo $array2['text']; ?>
</a>
<?php
$i++;
if ($i == "c") {
$i = "a";
}
}
?>
</div>
</div>
<?php
}
}
?>
</div>
So any ideas on why my code is not doing it?