We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

weird sql query

this line of query run in php get the right result which is 4 but I use it in php will only get 1..how come?

function totalrental(){

        $result = mysql_query("SELECT SUM(Rent_time) FROM product") or die (mysql_error());
        $count = mysql_num_rows($result);

        if ($count >= 1){

        echo $count;    
        }else{
            echo "0";
        }
}
2
Contributors
1
Reply
5 Minutes
Discussion Span
9 Months Ago
Last Updated
2
Views
Question
Answered
devianleong
Light Poster
44 posts since Dec 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Self-Answered as of 9 Months Ago

Because the SQL statement returns one row. It is just that the one row has a value of 4. You aren't getting 4 rows back with the sum keyword.

JorgeM
Senior Poster
3,996 posts since Dec 2011
Reputation Points: 294
Solved Threads: 543
Skill Endorsements: 115

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0564 seconds using 2.66MB