Like this code?
Show the author your appreciation.
This is the simple but more attractive polling system ver 1.0 in this version i can't add the admin section by the next version it will be avaiable.
The include files, sql statement are also found in the attached file.
host_conf.php
<?
$host = "localhost" ;
$user_name = "username" ;
$password = "password" ;
$db = "database" ;
define ( "C_DB_HOST" , $host );
define ( "C_DB_USER" , $user_name );
define ( "C_DB_PASS" , $password );
define ( "C_DB_NAME" , $db );
// Table Defination
define ( "TBL_NEWS" , "huforn_news" );
?>
mysql.lib.php
<?php
/*******************
Mr. Suraj Thapaliya
PHP Programmer
http://www.surajthapaliya.com.np
*/
class db
{
var $Host = C_DB_HOST ; // Hostname of our MySQL server
var $Database = C_DB_NAME ; // Logical database name on that server
var $User = C_DB_USER ; // Database user
var $Password = C_DB_PASS ; // Database user's password
var $Link_ID = 0 ; // Result of mysql_connect()
var $Query_ID = 0 ; // Result of most recent mysql_query()
var $Record = array(); // Current mysql_fetch_array()-result
var $Row ; // Current row number
var $Errno = 0 ; // Error state of query
var $Error = "" ;
function halt ( $msg )
{
echo( "</TD></TR></TABLE><B>Database error:</B> $msg <BR>\n" );
echo( "<B>MySQL error</B>: $this -> Errno ( $this -> Error )<BR>\n" );
die( "Session halted." );
}
function connect ()
{
if( $this -> Link_ID == 0 )
{
$this -> Link_ID = mysql_connect ( $this -> Host , $this -> User , $this -> Password );
if (! $this -> Link_ID )
{
$this -> halt ( "Link_ID == false, connect failed" );
}
$SelectResult = mysql_select_db ( $this -> Database , $this -> Link_ID );
if(! $SelectResult )
{
$this -> Errno = mysql_errno ( $this -> Link_ID );
$this -> Error = mysql_error ( $this -> Link_ID );
$this -> halt ( "cannot select database <I>" . $this -> Database . "</I>" );
}
}
}
function query ( $Query_String )
{
$this -> connect ();
$this -> Query_ID = mysql_query ( $Query_String , $this -> Link_ID );
$this -> Row = 0 ;
$this -> Errno = mysql_errno ();
$this -> Error = mysql_error ();
if (! $this -> Query_ID )
{
$this -> halt ( "Invalid SQL: " . $Query_String );
}
return $this -> Query_ID ;
}
function query_fetch ( $fetch = 0 )
{
if( $fetch == 0 ) {
$result =@ mysql_fetch_assoc ( $this -> Query_ID );
} else {
$result =@ mysql_fetch_array ( $this -> Query_ID );
}
if(! is_array ( $result ))
return false ;
$this -> total_field = mysql_num_fields ( $this -> Query_ID );
foreach( $result as $key => $val ){
$result [ $key ]= trim ( htmlspecialchars ( $val ));
}
return $result ;
}
function num_field ()
{
return mysql_num_fields ( $this -> Query_ID );
}
/*
function fetch_field()
{
return mysql_fetch_field($this->Query_ID,2);
}
*/
function next_record ()
{
$this -> Record = mysql_fetch_array ( $this -> Query_ID );
$this -> Row += 1 ;
$this -> Errno = mysql_errno ();
$this -> Error = mysql_error ();
$stat = is_array ( $this -> Record );
if (! $stat )
{
mysql_free_result ( $this -> Query_ID );
$this -> Query_ID = 0 ;
}
return $this -> Record ;
}
function num_rows ()
{
return mysql_num_rows ( $this -> Query_ID );
}
function maxRow ( $tablename , $field )
{
$sql = "select max( $field ) from $tablename " ;
$this -> query ( $sql );
$result =@ mysql_fetch_array ( $this -> Query_ID );
return $result [ 0 ];
}
function affected_rows ()
{
return mysql_affected_rows ( $this -> Link_ID );
}
function optimize ( $tbl_name )
{
$this -> connect ();
$this -> Query_ID = @ mysql_query ( "OPTIMIZE TABLE $tbl_name " , $this -> Link_ID );
}
function clean_results ()
{
if( $this -> Query_ID != 0 ) mysql_freeresult ( $this -> Query_ID );
}
function close ()
{
if( $this -> Link_ID != 0 ) mysql_close ( $this -> Link_ID );
}
}
?>
SQL Structure
CREATE TABLE polling (
poll varchar(50) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `polling`
--
INSERT INTO polling VALUES ('What is the main objective of Democracy');
INSERT INTO polling VALUES ('Peace');
INSERT INTO polling VALUES ('Constitution');
INSERT INTO polling VALUES ('Republic');
INSERT INTO polling VALUES ('Nation');
CREATE TABLE poll (
result varchar(100) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `poll`
--
INSERT INTO poll VALUES ('Constitution');
INSERT INTO poll VALUES ('Constitution');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Nation');
INSERT INTO poll VALUES ('Republic');
INSERT INTO poll VALUES ('Department of Employment');
INSERT INTO poll VALUES ('Constitution');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Constitution');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
INSERT INTO poll VALUES ('Peace');
poll.php
<table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="275" valign="top" style="border-right:1.5px solid #cccccc;">
<form name="form1" method="post" action="<? $PHP_SELF ?> ">
<table width="275" border="0" align="center" cellpadding="0" cellspacing="0">
<?
include ( "lib/host_conf.php" );
include ( "lib/mysql.lib.php" );
$objp =new db ;
$objp -> connect ();
$query = "select * from polling" ;
$objp -> query ( $query );
$i = 0 ;
$option =array();
while( $row = $objp -> query_fetch ( 1 ))
{
$result = $row [ 0 ];
$option [ $i ]= $result ;
if( $i == 0 )
{ ?>
<tr>
<td colspan="2"><? echo( " $row [ 0 ] " ); ?> </td>
</tr>
<? }
else
{ ?>
<tr>
<td valign="bottom">
<input name="poll" type="radio" class="pollingcheckbox" value="<? echo( $result ); ?> ">
<? echo( " $option [ $i ] " ); ?>
<?
}
$i ++;
}
?>
<br>
</td>
</tr>
<tr>
<td colspan="2">
<input name="Submit2" type="submit" class="newsdate" value="Vote">
</td>
</tr>
<?
$result = $_POST [ "poll" ];
if( strlen ( $result )> 1 )
{
$query_insert = "insert into poll (result) values (' $result ')" ;
$objp -> query ( $query_insert );
}
?>
</table>
</form></td>
<td width="275" valign="top"><?
echo "<table width=275>" ;
$obj =new db ;
$obj -> connect ();
$obj1 =new db ;
$obj1 -> connect ();
$vote =array();
$vote_option =array();
$perc =array();
$i = 0 ;
$total = 0 ;
$query = "select * from polling LIMIT 1,10" ;
$obj -> query ( $query );
while( $row = $obj -> query_fetch ( 1 ))
{
$option = $row [ "poll" ];
$vote_option [ $i ]= $option ;
$query_result = "select COUNT(result) from poll where result=' $option '" ;
$obj1 -> query ( $query_result );
while( $row_result = $obj1 -> query_fetch ( 1 ))
{
$vote [ $i ]= $row_result [ 0 ];
}
$total = $total + $vote [ $i ];
$i ++;
}
?>
<?
for( $j = 0 ; $j < $i ; $j ++)
{
$perc [ $j ]=(( $vote [ $j ]/ $total )* 100 );
?>
<?
echo "<tr><td>" .( $vote_option [ $j ]);
?>
<td><img src="picture/poll.gif" width="<? echo( $perc [ $j ]); ?> " height="8">
<?
echo "<td>" .( $vote [ $j ]. " votes" ). "</tr>" ;
}
echo "<tr><td colspan=2> <class=pollingresultred><strong>Total Votes: $total </strong></tr>" ;
echo "</table>" ;
?> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases , MySQL , Complete Programs , PHP , Databases Simple Mini Poll class library (SimPoll) Categories : PHP , PHP Classes , Databases , MySQL , Complete Programs Create and restore backup of MySQL databases Categories : MySQL , Databases , PHP , PHP Classes , Complete Programs A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP , PHP Classes , Databases , MySQL , HTML and PHP Education Center is a set of PHP-scripts to administer a corporate education and examination system via Internet/intranet written in PHP for MySQL.
Categories : PHP , Databases , MySQL , Complete Programs Simple database class Categories : PHP , PHP Classes , MySQL , Databases myCSV-dump converts a simple CSV-flatfile-database into an MySQL-dump. Categories : PHP , MySQL , Databases , Complete Programs AITSH Download Categories : PHP , Complete Programs , MySQL , Databases Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible Categories : PHP , PHP Classes , Databases , MySQL , MS SQL Server DDN FFA Network Script Categories : PHP , MySQL , Complete Programs , HTML and PHP , Databases Web Self Service Resource Scheduler Using Session Variables under php4 includes Calendar building code - requires MySQL Categories : PHP , Complete Programs , Calendar , MySQL , Databases Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP , PHP Classes , Databases , MySQL , Navigation MySQL Handler Categories : PHP , Databases , MySQL , Classes and Objects , PHP Classes DirtSearch Version 3.5 full function robust PHP and MySQL (and other
databases) Site or Web Wide Search Engine
Categories : PHP , MySQL , Complete Programs , Search , Databases