http://www.prcheckingtool.com

Minggu, 22 Mei 2011

Create a Simple Polling with PHP


PollingMany of us find the poll application in various websites. But the question is, how seh how to create simple poll application with PHP and integrate with the database (sql)? It's easy really, if we understand the flow of the algorithm: D

Well, let me direct .. do not confuse us aja deh tuk practices create a simple poll application using PHP and integrate with the database (sql).

For the record, the application of this poll is a plagiarism from the Web Counter Simplified script already written lamaaaa once. (Animashaun, eh?) concept is still the same right? If there is action, then its value will increase 1.

Okay, as for the materials to be prepared are:
- A database.
- A table.
?
1
2
3
4
5

create table poll (
id int (2) auto_increment primary key,
options varchar (30) not null,
int number (9) not null
);

Clearly, the column data type must be a integer number, to avoid any form of input other than numbers. And why should 9? Yes maybe there'll be more than 99 million people who gave him the poll results:)

Okeh, the table already, then what is needed is to provide some records. The authors give two (2) first course well.
?
1

insert into polling PHP values ​​('',' ', 0), ('',' HTML', 0);

Then we must create a form pollingnya.
?

poll.php
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aplikasi Polling Sederhana | AaEzha.com - Free Daily Nerd Tutorials</title>
</head>
 
<body>
<form id="form1" name="form1" method="post" action="polls.php">
  <p>Polling : Apa pelajaran favorit-mu?</p>
  <p>
    <input type="radio" name="pol" id="PHP" value="PHP" />
    PHP<br />
    <input type="radio" name="pol" id="HTML" value="HTML" />
    HTML</p>
  <p>
    <input type="submit" name="button" id="button" value="Submit" />
  </p>
</form>
</body>
</html>
then proses action:
polls.php
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?
mysql_connect('localhost','root',''); mysql_select_db('database');
$pol = $_POST['pol'];
 
$query = "select jumlah from polling where opsi='$pol'";
$result = mysql_query($query);
$tcount = mysql_fetch_array($result);
 
// Fungsi agar terus bertambah 1 tiap ada aksi
$tcount = $tcount["jumlah"]+1;
 
// Mengupdate jumlah vote pada opsi tertentu
$query1 = "update polling SET jumlah='$tcount' where opsi='$pol'";
$result1 = mysql_query($query1);
 
// Menampilkan jumlah voting dari tiap-tiap opsi
echo "<h2><p align='center'>Total vote untuk $pol sementara adalah : ".$tcount." suara</p></h2>";
echo "Hasil voting sementara adalah:";
 
$html = mysql_fetch_array(mysql_query("select jumlah from polling where opsi='HTML'"));
echo "<br>HTML : ".$html['jumlah']." suara";
 
$php = mysql_fetch_array(mysql_query("select jumlah from polling where opsi='PHP'"));
echo "<br>HTML : ".$php['jumlah']." suara";
?>

It was, klo with the above application, for any Election classmates do not need to spend money for paper, boxes, and others. It is a 'wetland' to the rats office: p

Oh yes, the full script can be downloaded here alone.
by
http://www.aaezha.com/membuat-polling-sederhana-dengan-php#more-2022

Tidak ada komentar:

Posting Komentar