By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Count the number of votes in a row

P: 2
Hello every one is there any body that could help me in the fillowing code.
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="vertrigo"; // Mysql password
$db_name="voting"; // Database name
$tbl_name="result"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Connect to the database
db_connect();

// Query the database and get the count
$result = mysql_query("SELECT rp1,rp2 count(*) FROM result group by rp1,rp2");
$num_rows = mysql_num_rows($result);

// Display the results
echo $num_rows;

?>
.I want to count the number of votes in a row .But i have aproblem to count votes.Please help me
May 31 '07 #1
Share this Question
Share on Google+
3 Replies


DeMan
100+
P: 1,806
Hi meti,

Welcome to thescripts. I'm sure you will find a host of knowledge in the various forums. You can find these forums by selecting the options on the blue bar near the to of the screen.

I will move this post to the PHP forum for you....
May 31 '07 #2

Motoma
Expert 2.5K+
P: 3,235
Hello every one is there any body that could help me in the fillowing code.
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="vertrigo"; // Mysql password
$db_name="voting"; // Database name
$tbl_name="result"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Connect to the database
db_connect();

// Query the database and get the count
$result = mysql_query("SELECT rp1,rp2 count(*) FROM result group by rp1,rp2");
$num_rows = mysql_num_rows($result);

// Display the results
echo $num_rows;

?>
.I want to count the number of votes in a row .But i have aproblem to count votes.Please help me
I need a little more information as to what your database holds. Could you give an example of both what is in the table and what the query is returning?
Jun 1 '07 #3

ak1dnar
Expert 100+
P: 1,584
There is a error here.
[PHP]
$result = mysql_query("SELECT rp1,rp2 count(*) FROM result group by rp1,rp2");
$num_rows = mysql_num_rows($result);

echo $num_rows;
[/PHP]

Note: rp1,rp2 then " , " should come before count(*)
[PHP]
$result = mysql_query("SELECT rp1,rp2,count(*) FROM result group by rp1,rp2");[/PHP]

How ever No use of using this count(*).

mysql_num_rows will give the results that you need.
Jun 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.