web_master Posted February 9, 2008 Share Posted February 9, 2008 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]; } } ?> Quote Link to comment Share on other sites More sharing options...
web_master Posted February 9, 2008 Author Share Posted February 9, 2008 $kamera_id = mysql_insert_id(); => $poll_id = mysql_insert_id(); mistake Quote Link to comment Share on other sites More sharing options...
web_master Posted February 9, 2008 Author Share Posted February 9, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.