Skip to content

Instantly share code, notes, and snippets.

View wichaksono's full-sized avatar
🤔
Coding Is Fun.. Right ?

Wakhid Wichaksono wichaksono

🤔
Coding Is Fun.. Right ?
View GitHub Profile
<?php
/**
* getPolling adalah fungsi untuk mengambil dan menambilkan
* poling atau hasil vote yang diperoleh, sekaligus di convert
* kedalam persen
*
* @param int $id id_opsi
* @return string
*/
function getPolling($id)
<?php
require_once 'config.php';
if (isset($_GET['nomer']) && ! empty($_GET['nomer'])) {
$nomerVote = $_GET['nomer'];
// sql untuk menambahkan vote kedatabase
$sql = "INSERT INTO voting (id_opsi, date_create) VALUES ('$nomerVote', NOW()) ";
$insert = $connect->query($sql);
if ($insert) {
<?php
// koneksi database
require 'config.php';
?>
<html>
<head>
<title>Sistem Vote</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'votes';
$connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($connect->connect_error) {
die('Error Koneksi : ' . $connect->connect_error);
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
// ...
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
// ...
// ...
// nilai default bila $instance['title'] belum diset / kosong (empty)
$title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'New title' );
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
type="text" value="<?php echo esc_attr( $title ); ?>">
</p>
// ....
$widget_html = $args['before_widget'];
$nama = "";
if ( ! empty( $instance['title'] ) ) {
$widget_html .= $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
$nama = $instance['title'];
}
$widget_html .= "<b>Nama Widget : </b> " . $nama;
<?php
class My_Widget extends WP_Widget {
/**
* Mengatur Nama Widget
*/
public function __construct() {
$widget_ops = array(
'classname' => 'my_widget', // class pada html
'description' => 'My Widget is awesome', // deskripsi tentang widget
Sekarang Jam <time>19:00</time>.