Jump to content

[SOLVED] Poll counting


web_master

Recommended Posts

Hi,

 

I want to made a poll counter. The database contains:

 

id,

poll_yes_no (CHAR) 1

 

When somebody polling there is in `poll_yes_no` row '1' or '0'.

 

Well, I want to count and print the zeros (0) and ones (1).

 

(or I made separatelly two rows `poll_yes` and `poll_no`)

 

<?php
// Insert into dBase
$query_return = mysql_query("
INSERT INTO `poll` (
	`poll_yes_no`,
	`poll_datetime`,
	`poll_ip`
) VALUES (
	'".$_POST['poll_yes_no']."',
	'".date("Y-m-d H:i:s")."',
	'".getenv("REMOTE_ADDR")."'
)");

if(!$query_return){
	print mysql_error();
	exit;
}

$kamera_id = mysql_insert_id();

// Reload from dBase
$query_return = mysql_query("SELECT DISTINCT `poll_yes_no` FROM `poll`");

if(!$query_return){
	print mysql_error();
	exit;
}

while($row = mysql_fetch_row($result)) {

	for($i = 0; $i < count($row); $i++) {
		print $row[$i];
	}
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/90189-solved-poll-counting/
Share on other sites

Resolved!

 

I made a mistake with a mysql_fetch_row... here is a script that work:

 

 

<?php
// Reload from dBase
$result_0 = mysql_query("SELECT `poll_yes_no` FROM `poll` WHERE `poll_yes_no` = '0'");

if(!$result_0){
	print mysql_error();
	exit;
}

$row_0 = mysql_num_rows($result_0);

print $row_0;

// Reload from dBase
$result_1 = mysql_query("SELECT `poll_yes_no` FROM `poll` WHERE `poll_yes_no` = '1'");

if(!$result_1){
	print mysql_error();
	exit;
}

$row_1 = mysql_num_rows($result_1);

print $row_1;

?>

Link to comment
https://forums.phpfreaks.com/topic/90189-solved-poll-counting/#findComment-462505
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.