WP_Query parameters not working? - wordpress-theming

So I'm trying to get pagination correct for my wordpress site so categories and pages display the correct posts :
wp_reset_query();
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky = get_option( 'sticky_posts' );
$args = array(
'ignore_sticky_posts' => 1,
'posts_per_page' => 10,
'orderby' => 'date',
'post__not_in' => $sticky,
'paged' => $paged,
);
$query = new WP_Query( $args );
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
I get the posts to display but the following parameters :
'ignore_sticky_posts' => 1,
'posts_per_page' => 10,
'orderby' => 'date',
'post__not_in' => $sticky,
does not seem to work... any idea why ?

Chances are you don't need wp_reset_query() at the top unless you are overriding the global $wp_query somewhere else in your code.
When you are creating a custom query you need to use that throughout your loop. In your case that is $query so we need to use that when calling have_posts(), the_post(), and max_num_pages
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky = get_option( 'sticky_posts' );
$args = array(
'ignore_sticky_posts' => 1,
'posts_per_page' => 10,
'orderby' => 'date',
'post__not_in' => $sticky,
'paged' => $paged,
);
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
// interact with the post here
<?php endwhile; ?>
<?php endif; ?>
// we overwrote the global $post when called the_post(); so we need to reset that
<?php wp_reset_postdata(); ?>
// again we need to reference our custom query for our pagination
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $query->max_num_pages
) );
?>

Related

How to Get WooCommerce Product Name with WP_Query?

I am trying to use this code on "Wp All Import". If there is a product name in the database, that product should be omitted, but the code will not work as is. What do I need to do for the code to work?
add_filter('wp_all_import_is_post_to_create', 'create_only_if_unique_custom_field', 10, 3);
function create_only_if_unique_custom_field( $continue_import, $data, $import_id ) {
// Only run for import ID 1.
if ( $import_id == 33 || $import_id == 34 ) {
// The custom field to check.
$key_to_look_up = "post_title";
// The value to check where 'num' is the element name.
$value_to_look_up = $data['name'];
// Prepare the WP_Query arguments
$args = array (
// Set the post type being imported.
'post_type' => array( 'post' ),
// Check our custom field for our value.
'meta_query' => array(array(
'key' => $key_to_look_up,
'value' => $value_to_look_up,
)),
);
// Run the query and do not create post if custom field value is duplicated.
$query = new WP_Query( $args );
return !($query->have_posts());
} else {
// Take no action if a different import ID is running.
return $continue_import;
}
}
You can do like this.
<?php
$params = array('posts_per_page' => 5);
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata();?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
There are some ways to show the different types of Woocommerce product names with WP_Query.
<?php
//Pulling WooCommerce Products instead of WordPress Posts, Use this param
$params = array(
'posts_per_page' => 5,
'post_type' => 'product'
);
//Displaying products of a given price range, use this param
$params = array(
'posts_per_page' => 100,
'post_type' => array('product', 'product_variation'),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_price',
'value' => 5,
'compare' => '<=',
'type' => 'NUMERIC'
),
array(
'key' => '_sales_price',
'value' => 5,
'compare' => '<=',
'type' => 'NUMERIC'
)
)
);
//Displaying available products only, use this param
$params = array(
'posts_per_page' => 5,
'post_type' => array('product', 'product_variation'),
'meta_query' => array(
array(
'key' => '_price',
'value' => 5,
'compare' => '<',
'type' => 'NUMERIC'
),
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
);
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) :
while ($wc_query->have_posts()) :
$wc_query->the_post();
the_title();
endwhile;
endif;
Also will help you the article https://www.gavick.com/blog/wp_query-woocommerce-products
Thank you
This variable controls the title.
// Xml file column name
$value = = $data['product_title'];
// Get wpdb product title
$posts = get_posts([
'post_type' => 'product',
'title' => $value,
]);

put spans and divs around paginate_links

I wanna style my links and in order to do that I need some spans and divs around it but I dunno how it's done when using paginate_links() from WordPress.
Can you help me to do that?
<div class="pagination">
<?php echo
$pagination = paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('← Previous'),
'next_text' => __('Next →'),
'total' => ceil($total / $items_per_page),
'current' => $page,
'type' => 'plain'
));
?>
</div>
so far it looks like that
Just change li to div / span whatever. The main difference is to change your "type" from "plain" to "array" and then you can do what you want with it.
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
$prev_next = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => __('← Previous'),
'next_text' => __('Next →')
) );
if($prev_next){ ?>
<ul>
<?php
foreach($prev_next as $key=>$val){
if (strpos($val,"'page-numbers current'") !== false) {
echo '<li class="active item">'.$val.'</li>';
} elseif (strpos($val,'"next page-numbers"') !== false || strpos($val,'"prev page-numbers"') !== false ) {
echo'<li>'.$val.'</li>';
} else {
echo '<li class="item">'.$val.'</li>';
}
} ?>
</ul>
<?php } ?>

WP query retrieve the src of the attached image

I'm encoding in JSON a bunch of data from a WP Query:
$args = array(
'posts_per_page' => 20,
'post_type' => 'post',
'category' => 6,
'meta_key' => 'custom_total_hits',
'tag' => 'indie-pop',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'date_query' => array(
'after' => date('Y-m-d', strtotime('-40 days'))
)
);
$query = new WP_Query( $args );
$posts = $query->get_posts();
foreach( $posts as $post ) {
$output[] = array(
'id' => $post->ID,
'title' => $post->post_title,
'count' => $post->custom_total_hits,
'soundcloud_url' => $post->soundcloud_song,
'soundcloud_id' => $post->soundcloud_ids,
'link' => get_permalink($post),
);
}
echo json_encode($output);
I would like to display in my JSON a key corrisponding to the src of the medium size of the attached image. If I use 'images' => get_attached_media('image', $post->ID) it retrives an array of multiple data which I can not access since I don't know the ID of the attached image when I process the data of my JSON. How can I do to retrieve a first level key - value where the value is the src of the attached image?
get_post_thumbnail_id : Get post thumbnail ID
wp_get_attachment_url : Get attachment URL by attachment id
'images' => parse_url( wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ) );
Would you please try above code?
Try this solution:
$images = array();
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
foreach (get_intermediate_image_sizes() as $size) {
$images[$size] = wp_get_attachment_image_src($post_thumbnail_id, $size);
}
//end
'images' => $images // type_of_size => image_url

cakephp instead of user_id how do I get for instance username in the view

I have 3 tables: users, comments and videos.
In my videos view.ctp I can't get the username displayed, only the user_id.
I can't figure it out, can someone point me in the right direction?
User model:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'user_id',
'dependent' => false
),
}
Video model:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'video_id',
'dependent' => false
),
}
Comment model:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
),
'Video' => array(
'className' => 'Video',
'foreignKey' => 'video_id'
)
);
}
Videos view.ctp
<?php if (!empty($video['Comment'])): ?>
<?php foreach ($video['Comment'] as $comment): ?>
<p><?php echo $comment['comment_created']; ?></p>
<p><?php echo $comment['User']['user_username']; ?></p>
<p><?php echo $comment['user_id']; ?></p>
<p><?php echo $comment['comment_body']; ?></p>
<?php endforeach; ?>
<?php endif; ?>
VideosController
public function view($id = null) {
$this->loadModel('Comment');
if (!$this->Video->exists($id)) {
throw new NotFoundException(__('Invalid video'));
}
$options = array('conditions' => array('Video.' . $this->Video->primaryKey => $id));
$this->set('video', $this->Video->find('first', $options));
$current_user = $this->Auth->user('user_id');
if ($this->request->is('post')) {
$this->Comment->create();
/*save the current's user id in database*/
$this->Comment->set('user_id', $current_user);
/*save the current's video id in database*/
$this->Comment->set('video_id', $id);
if ($this->Comment->save($this->request->data)) {
$this->Session->setFlash(__('You\'re comment has been placed.'));
return $this->redirect(array('action' => 'view/' . $id));
} else {
$this->Session->setFlash(__('You\'re comment could not be placed. Please, try again.'));
}
}
$this->set(compact('users', 'videos'));
}
Solution:
In the controller:
$comments = $this->Video->Comment->find('all', array('conditions' => array('Comment.video_id' => $id)));
In the view:
<?php foreach ($comments as $comment): ?>
<p><?php echo $comment['User']['user_username']; ?></p>
<p><?php echo $comment['Comment']['comment_created']; ?></p>
<p><?php echo $comment['Comment']['comment_body']; ?></p>
<?php endforeach; ?>

Trigger and form codeigniter

I have a database and form with some trigger in phpmyadmin. When I input the value manually on phpmyadmin, the trigger is executed normally. The problem is, when I input the value by form I made with codeigniter, the trigger is not executed, and there is no error. Can anybody help me?
This is the controller
<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
class Pengujian extends MY_Controller
{
public $data = array(
'modul' => 'pengujian',
'breadcrumb' => 'Pengujian',
'pesan' => '',
'pagination' => '',
'tabel_data' => '',
'main_view' => 'view_pengujian/pengujian_view',
'form_action' => '',
'form_value' => '',
'option_uji' => '',
);
public function __construct()
{
parent::__construct();
$this->load->model('Pengujian_model', 'pengujian', TRUE);
$this->load->model('Peralatan_model', 'peralatan', TRUE);
$this->load->model('Penerangan_model', 'penerangan', TRUE);
$this->load->model('Kemudi_model', 'kemudi', TRUE);
$this->load->model('Suspensi_model', 'suspensi', TRUE);
$this->load->model('Banpelek_model', 'banpelek', TRUE);
$this->load->model('Rangka_model', 'rangka', TRUE);
$this->load->model('Rem_model', 'rem', TRUE);
$this->load->model('Gasbuang_model', 'gasbuang', TRUE);
$this->load->model('Mesin_model', 'mesin', TRUE);
$this->load->model('Lainlain_model', 'lainlain', TRUE);
$this->load->model('Lainlain2_model', 'lainlain2', TRUE);
$this->load->model('Akhir_model', 'akhir', TRUE);
$this->load->helper('form');
//$this->load->model('Penguji_model', 'penguji', TRUE);
}
public function index($offset = 0)
{
$this->session->unset_userdata('no_pengujian_sekarang', '');
$pengujian = $this->pengujian->cari_semua($offset);
if ($pengujian)
{
$tabel = $this->pengujian->buat_tabel($pengujian);
$this->data['tabel_data'] = $tabel;
$this->data['pagination'] = $this->pengujian->paging(site_url('pengujian/halaman'));
}
else
{
$this->data['pesan'] = 'Tidak ada data pengujian';
}
$this->load->view('template', $this->data);
}
public function tambah1()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Awal';
$this->data['main_view'] = 'view_pengujian/pengujian_form';
$this->data['form_action'] = 'pengujian/tambah1';
if($this->input->post('submit'))
{
if($this->pengujian->validasi_tambah())
{
if($this->pengujian->tambah1())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah2');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
public function tambah2()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Peralatan';
$this->data['main_view'] = 'view_pengujian/peralatan_form';
$this->data['form_action'] = 'pengujian/tambah2';
if($this->input->post('submit'))
{
if($this->peralatan->validasi_tambah())
{
if($this->peralatan->tambah2())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah3');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
I have until tambah12 methods, for each method, it must load from 12 models too, and 12 forms.
This is model
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no pengujian',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
public function tambah1()
{
$pengujian = array(
'NO_PENGUJIAN' => $this->input->post('NO_PENGUJIAN'),
'NO_PEMERIKSAAN' => $this->input->post('NO_PEMERIKSAAN'),
'LOKASI_PENGUJIAN' => $this->input->post('LOKASI_PENGUJIAN'),
'NO_KODE' => $this->input->post('NO_KODE'),
'NO_KENDARAAN' => $this->input->post('NO_KENDARAAN'),
'PEMILIK_KENDARAAN' => $this->input->post('PEMILIK_KENDARAAN'),
'TYPE_MERK_PABRIK' => $this->input->post('TYPE_MERK_PABRIK'),
'JENIS_KENDARAAN' => $this->input->post('JENIS_KENDARAAN'),
'MULAI_DIPERGUNAKAN' => $this->input->post('MULAI_DIPERGUNAKAN'),
'NO_LAPORAN' => $this->input->post('NO_LAPORAN'),
'JENIS_PEMERIKSAAN' => $this->input->post('JENIS_PEMERIKSAAN'),
'JARAK_PEMAKAIAN' => $this->input->post('JARAK_PEMAKAIAN'),
'BERAT_KENDARAAN' => $this->input->post('BERAT_KENDARAAN'),
'PERALATAN' => $this->input->post('PERALATAN'),
'SISTEM_PENERANGAN' => $this->input->post('SISTEM_PENERANGAN'),
'SISTEM_KEMUDI' => $this->input->post('SISTEM_KEMUDI'),
'AS_DAN_SUSPENSI' => $this->input->post('AS_DAN_SUSPENSI'),
'BAN_DAN_PELEK' => $this->input->post('BAN_DAN_PELEK'),
'RANGKA_DAN_BODI' => $this->input->post('RANGKA_DAN_BODI'),
'SISTEM_REM' => $this->input->post('SISTEM_REM'),
'SISTEM_REM_GAS_BUANG' => $this->input->post('SISTEM_REM_GAS_BUANG'),
'MESIN_TRANSMISI' => $this->input->post('MESIN_TRANSMISI'),
'LAIN_LAIN' => $this->input->post('LAIN_LAIN'),
'LAIN_LAIN2' => $this->input->post('LAIN_LAIN2')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $pengujian);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
and this
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Peralatan_model extends CI_Model
{
public $db_tabel ='peralatan';
//public $offset = 0;
//public function cari_semua($offset = 0);
public function tambah2()
{
$peralatan = array(
'NO_CHASIS' => $this->input->post('NO_CHASIS'),
'PLAT_PABRIK_PEMBUAT' => $this->input->post('PLAT_PABRIK_PEMBUAT'),
'PLAT_NOMOR' => $this->input->post('PLAT_NOMOR'),
'TULISAN' => $this->input->post('TULISAN'),
'PENGHAPUS_KACA_DEPAN' => $this->input->post('PENGHAPUS_KACA_DEPAN'),
'KLAKSON' => $this->input->post('KLAKSON'),
'KACA_SPION' => $this->input->post('KACA_SPION'),
'PANDANGAN_KE_DEPAN' => $this->input->post('PANDANGAN_KE_DEPAN'),
'KACA_PENAHAN_SINAR' => $this->input->post('KACA_PENAHAN_SINAR'),
'ALAT_PENGENDALIAN' => $this->input->post('ALAT_PENGENDALIAN'),
'LAMPU_INDIKASI' => $this->input->post('LAMPU_INDIKASI'),
'SPEEDOMETER' => $this->input->post('SPEEDOMETER'),
'PERLENGKAPAN' => $this->input->post('PERLENGKAPAN')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $peralatan);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no chasis',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
}
this is the form
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no pemeriksaan' => array(
'name' => 'NO_PEMERIKSAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PEMERIKSAAN', isset($form_value['NO_PEMERIKSAAN']) ? $form_value['NO_PEMERIKSAAN'] : '')),
'lokasi pengujian' => array(
'name' => 'LOKASI_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('LOKASI_PENGUJIAN', isset($form_value['LOKASI_PENGUJIAN']) ? $form_value['LOKASI_PENGUJIAN'] : '')),
'no kode' => array(
'name' => 'NO_KODE',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KODE', isset($form_value['NO_KODE']) ? $form_value['NO_KODE'] : '')),
'no kendaraan' => array(
'name' => 'NO_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KENDARAAN', isset($form_value['NO_KENDARAAN']) ? $form_value['NO_KENDARAAN'] : '')),
'pemilik kendaraan' => array(
'name' => 'PEMILIK_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('PEMILIK_KENDARAAN', isset($form_value['[PEMILIK_KENDARAAN]']) ? $form_value['PEMILIK_KENDARAAN'] : '')),
'type merk pabrik' => array(
'name' => 'TYPE_MERK_PABRIK',
'size' => '30',
'class' => 'form_field',
'value' => set_value('TYPE_MERK_PABRIK', isset($form_value['TYPE_MERK_PABRIK']) ? $form_value['TYPE_MERK_PABRIK'] : '')),
'jenis kendaraan' => array(
'name' => 'JENIS_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JENIS_KENDARAAN', isset($form_value['JENIS_KENDARAAN']) ? $form_value['JENIS_KENDARAAN'] : '')),
'mulai dipergunakan' => array(
'name' => 'MULAI_DIPERGUNAKAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('MULAI_DIPERGUNAKAN', isset($form_value['MULAI_DIPERGUNAKAN']) ? $form_value['MULAI_DIPERGUNAKAN'] : '')),
'no laporan' => array(
'name' => 'NO_LAPORAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_LAPORAN', isset($form_value['NO_LAPORAN']) ? $form_value['NO_LAPORAN'] : '')),
'jenis pemeriksaan' => array(
'name' => 'JENIS_PEMERIKSAAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('JENIS_PEMERIKSAAN', isset($_POST['JENIS_PEMERIKSAAN']))),
'jarak pemakaian' => array(
'name' => 'JARAK_PEMAKAIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JARAK_PEMAKAIAN', isset($form_value['JARAK_PEMAKAIAN']) ? $form_value['JARAK_PEMAKAIAN'] : '')),
'berat kendaraan' => array(
'name' => 'BERAT_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('BERAT_KENDARAAN', isset($form_value['BERAT_KENDARAAN']) ? $form_value['BERAT_KENDARAAN'] : '')),
'peralatan' => array(
'name' => 'PERALATAN',
'size' => '30',
'value' => set_value('PERALATAN', isset($form_value['PERALATAN']) ? $form_value['PERALATAN'] : '')),
'sistem penerangan' => array(
'name' => 'SISTEM_PENERANGAN',
'size' => '30',
'value' => set_value('SISTEM_PENERANGAN', isset($form_value['SISTEM_PENERANGAN']) ? $form_value['SISTEM_PENERANGAN'] : '')),
'sistem kemudi' => array(
'name' => 'SISTEM_KEMUDI',
'size' => '30',
'value' => set_value('SISTEM_KEMUDI', isset($form_value['SISTEM_KEMUDI']) ? $form_value['SISTEM_KEMUDI'] : '')),
'as dan suspensi' => array(
'name' => 'AS_DAN_SUSPENSI',
'size' => '30',
'value' => set_value('AS_DAN_SUSPENSI', isset($form_value['AS_DAN_SUSPENSI']) ? $form_value['AS_DAN_SUSPENSI'] : '')),
'ban dan pelek' => array(
'name' => 'BAN_DAN_PELEK',
'size' => '30',
'value' => set_value('BAN_DAN_PELEK', isset($form_value['BAN_DAN_PELEK']) ? $form_value['BAN_DAN_PELEK'] : '')),
'rangka dan bodi' => array(
'name' => 'RANGKA_DAN_BODI',
'size' => '30',
'value' => set_value('RANGKA_DAN_BODI', isset($form_value['RANGKA_DAN_BODI']) ? $form_value['RANGKA_DAN_BODI'] : '')),
'sistem rem' => array(
'name' => 'SISTEM_REM',
'size' => '30',
'value' => set_value('SISTEM_REM', isset($form_value['SISTEM_REM']) ? $form_value['SISTEM_REM'] : '')),
'sistem rem gas buang' => array(
'name' => 'SISTEM_REM_GAS_BUANG',
'size' => '30',
'value' => set_value('SISTEM_REM_GAS_BUANG', isset($form_value['SISTEM_REM_GAS_BUANG']) ? $form_value['SISTEM_REM_GAS_BUANG'] : '')),
'mesin transmisi' => array(
'name' => 'MESIN_TRANSMISI',
'size' => '30',
'value' => set_value('MESIN_TRANSMISI', isset($form_value['MESIN_TRANSMISI']) ? $form_value['MESIN_TRANSMISI'] : '')),
'lain lain' => array(
'name' => 'LAIN_LAIN',
'size' => '30',
'value' => set_value('LAIN_LAIN', isset($form_value['LAIN_LAIN']) ? $form_value['LAIN_LAIN'] : '')),
'lain lain2' => array(
'name' => 'LAIN_LAIN2',
'size' => '30',
'value' => set_value('LAIN_LAIN2', isset($form_value['LAIN_LAIN2']) ? $form_value['LAIN_LAIN2'] : '')),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Pemeriksaan', 'NO_PEMERIKSAAN'); ?>
<?php echo form_input($form['no pemeriksaan']); ?>
</p>
<?php echo form_error('NO_PEMERIKSAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Lokasi Pengujian', 'LOKASI_PENGUJIAN'); ?>
<?php echo form_input($form['lokasi pengujian']); ?>
</p>
<?php echo form_error('LOKASI_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kode', 'NO_KODE'); ?>
<?php echo form_input($form['no kode']); ?>
</p>
<?php echo form_error('NO_KODE', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kendaraan', 'NO_KENDARAAN'); ?>
<?php echo form_input($form['no kendaraan']); ?>
</p>
<?php echo form_error('NO_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Pemilik Kendaraan', 'PEMILIK_KENDARAAN'); ?>
<?php echo form_input($form['pemilik kendaraan']); ?>
</p>
<?php echo form_error('PEMILIK_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Type Merk Pabrik', 'TYPE_MERK_PABRIK'); ?>
<?php echo form_input($form['type merk pabrik']); ?>
</p>
<?php echo form_error('TYPE_MERK_PABRIK', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Kendaraan', 'JENIS_KENDARAAN'); ?>
<?php echo form_input($form['jenis kendaraan']); ?>
</p>
<?php echo form_error('JENIS_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Mulai Dipergunakan', 'MULAI_DIPERGUNAKAN'); ?>
<?php echo form_input($form['mulai dipergunakan']); ?>
</p>
<?php echo form_error('MULAI_DIPERGUNAKAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Laporan', 'NO_LAPORAN'); ?>
<?php echo form_input($form['no laporan']); ?>
</p>
<?php echo form_error('NO_LAPORAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Pemeriksaan', 'JENIS_PEMERIKSAAN'); ?>
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Utama'); ?> Utama
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Ulang'); ?> Ulang
</p>
<p>
<?php echo form_label('Jarak Pemakaian', 'JARAK_PEMAKAIAN'); ?>
<?php echo form_input($form['jarak pemakaian']); ?>
</p>
<?php echo form_error('JARAK_PEMAKAIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Berat Kendaraan', 'BERAT_KENDARAAN'); ?>
<?php echo form_input($form['berat kendaraan']); ?>
</p>
<?php echo form_error('BERAT_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
<?php echo var_dump($form["no pengujian"]); ?>
and this
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no chasis' => array(
'name' => 'NO_CHASIS',
'size' => '30',
'class' => 'radio',
'value' => set_value('NO_CHASIS', isset($_POST['NO_CHASIS']))),
'plat pabrik pembuat' => array(
'name' => 'PLAT_PABRIK_PEMBUAT',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_PABRIK_PEMBUAT', isset($_POST['PLAT_PABRIK_PEMBUAT']))),
'plat nomor' => array(
'name' => 'PLAT_NOMOR',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_NOMOR', isset($_POST['PLAT_NOMOR']))),
'tulisan' => array(
'name' => 'TULISAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('TULISAN', isset($_POST['TULISAN']))),
'penghapus kaca depan' => array(
'name' => 'PENGHAPUS_KACA_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PENGHAPUS_KACA_DEPAN', isset($_POST['PENGHAPUS_KACA_DEPAN']))),
'klakson' => array(
'name' => 'KLAKSON',
'size' => '30',
'class' => 'radio',
'value' => set_value('KLAKSON', isset($_POST['KLAKSON']))),
'kaca spion' => array(
'name' => 'KACA_SPION',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_SPION', isset($_POST['KACA_SPION']))),
'pandangan ke depan' => array(
'name' => 'PANDANGAN_KE_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PANDANGAN_KE_DEPAN', isset($_POST['PANDANGAN_KE_DEPAN']))),
'kaca penahan sinar' => array(
'name' => 'KACA_PENAHAN_SINAR',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_PENAHAN_SINAR', isset($_POST['KACA_PENAHAN_SINAR']))),
'alat pengendalian' => array(
'name' => 'ALAT_PENGENDALIAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('ALAT_PENGENDALIAN', isset($_POST['ALAT_PENGENDALIAN']))),
'lampu indikasi' => array(
'name' => 'LAMPU_INDIKASI',
'size' => '30',
'class' => 'radio',
'value' => set_value('LAMPU_INDIKASI', isset($_POST['LAMPU_INDIKASI']))),
'speedometer' => array(
'name' => 'SPEEDOMETER',
'size' => '30',
'class' => 'radio',
'value' => set_value('SPEEDOMETER', isset($_POST['SPEEDOMETER']))),
'perlengkapan' => array(
'name' => 'PERLENGKAPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PERLENGKAPAN', isset($_POST['PERLENGKAPAN']))),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Chasis', 'NO_CHASIS'); ?>
<?php echo form_radio('NO_CHASIS', 'Lulus'); ?> Lulus
<?php echo form_radio('NO_CHASIS', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Pabrik Pembuat', 'PLAT_PABRIK_PEMBUAT'); ?>
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Nomor', 'PLAT_NOMOR'); ?>
<?php echo form_radio('PLAT_NOMOR', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_NOMOR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Tulisan', 'TULISAN'); ?>
<?php echo form_radio('TULISAN', 'Lulus'); ?> Lulus
<?php echo form_radio('TULISAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Penghapus Kaca Depan', 'PENGHAPUS_KACA_DEPAN'); ?>
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Klakson', 'KLAKSON'); ?>
<?php echo form_radio('KLAKSON', 'Lulus'); ?> Lulus
<?php echo form_radio('KLAKSON', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Spion', 'KACA_SPION'); ?>
<?php echo form_radio('KACA_SPION', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_SPION', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Pandangan Ke Depan', 'PANDANGAN_KE_DEPAN'); ?>
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Penahan Sinar', 'KACA_PENAHAN_SINAR'); ?>
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Alat Pengendalian', 'ALAT_PENGENDALIAN'); ?>
<?php echo form_radio('ALAT_PENGENDALIAN', 'Lulus'); ?> Lulus
<?php echo form_radio('ALAT_PENGENDALIAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Lampu Indikasi', 'LAMPU_INDIKASI'); ?>
<?php echo form_radio('LAMPU_INDIKASI', 'Lulus'); ?> Lulus
<?php echo form_radio('LAMPU_INDIKASI', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Speedometer', 'SPEEDOMETER'); ?>
<?php echo form_radio('SPEEDOMETER', 'Lulus'); ?> Lulus
<?php echo form_radio('SPEEDOMETER', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Perlengkapan', 'PERLENGKAPAN'); ?>
<?php echo form_radio('PERLENGKAPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PERLENGKAPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
and this is the trigger form php myadmin
CREATE TRIGGER `trigger_peralatan` BEFORE INSERT ON `peralatan`
FOR EACH ROW begin
if (new.NO_CHASIS = "Lulus"
AND new.PLAT_PABRIK_PEMBUAT = "Lulus"
AND new.PLAT_NOMOR = "Lulus"
AND new.TULISAN = "Lulus"
AND new.PENGHAPUS_KACA_DEPAN = "Lulus"
AND new.KLAKSON = "Lulus"
AND new.KACA_SPION = "Lulus"
AND new.PANDANGAN_KE_DEPAN = "Lulus"
AND new.KACA_PENAHAN_SINAR = "Lulus"
AND new.ALAT_PENGENDALIAN = "Lulus"
AND new.LAMPU_INDIKASI = "Lulus"
AND new.SPEEDOMETER = "Lulus"
AND new.PERLENGKAPAN = "Lulus")
then
UPDATE pengujian
SET PERALATAN = "Lulus"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN;
else
UPDATE pengujian
SET PERALATAN = "Gagal"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN; end if;
end
and this for the last trigger
CREATE TRIGGER `trigger_nilai` BEFORE INSERT ON `pengujian`
FOR EACH ROW begin
if
(new.AS_DAN_SUSPENSI = "Lulus" AND
new.BAN_DAN_PELEK = "Lulus" AND
new.LAIN_LAIN = "Lulus" AND
new.LAIN_LAIN2 = "Lulus" AND
new.MESIN_TRANSMISI = "Lulus" AND
new.PERALATAN = "Lulus" AND
new.RANGKA_DAN_BODI = "Lulus" AND
new.SISTEM_KEMUDI = "Lulus" AND
new.SISTEM_PENERANGAN = "Lulus" AND
new.SISTEM_REM = "Lulus" AND
new.SISTEM_REM_GAS_BUANG = "Lulus")
then
SET new.PENILAIAN = "Lulus" ;
else
SET new.PENILAIAN = "Gagal" ; end if;
end
this is the insert query
INSERT INTO `pengujian`(`NO_PENGUJIAN`, `NO_PEMERIKSAAN`, `LOKASI_PENGUJIAN`, `NO_KODE`, `NO_KENDARAAN`, `PEMILIK_KENDARAAN`, `TYPE_MERK_PABRIK`, `JENIS_KENDARAAN`, `MULAI_DIPERGUNAKAN`, `TANGGAL_PEMERIKSAAN`, `NO_LAPORAN`, `JENIS_PEMERIKSAAN`, `JARAK_PEMAKAIAN`, `BERAT_KENDARAAN`, `PERALATAN`, `SISTEM_PENERANGAN`, `SISTEM_KEMUDI`, `AS_DAN_SUSPENSI`, `BAN_DAN_PELEK`, `RANGKA_DAN_BODI`, `SISTEM_REM`, `SISTEM_REM_GAS_BUANG`, `MESIN_TRANSMISI`, `LAIN_LAIN`, `LAIN_LAIN2`, `PENILAIAN`, `TANGGAL_PEMERIKSAAN_BERIKUTNYA`, `CATATAN`, `PENGUJI`, `BIAYA_TOTAL`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12],[value-13],[value-14],[value-15],[value-16],[value-17],[value-18],[value-19],[value-20],[value-21],[value-22],[value-23],[value-24],[value-25],[value-26],[value-27],[value-28],[value-29],[value-30])
It's a little confusing...