PHP - Moved: Mysql Counting
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=314776.0 Similar TutorialsHi everyone. I need to display a list of departments and a total of occurrences of each department in mysql/php. eg. There are 3 Administration types. There are 5 Government types. etc. there is no error when i run the code below, but nothing displays happens either. i'd appreciate anyone's help. Thanks. Code: [Select] <?php $query = mysql_query("SELECT CompanyName, CompanyBranch, DateRecorded, DateClosed, Year(DateRecorded) AS Year, CaseOwner.UsersDepartment FROM records LEFT JOIN CaseOwner ON CaseOwner = CaseOwner.ProperName GROUP BY CompanyName, CompanyBranch, DateRecorded, DateClosed, CaseOwner.UsersDepartment ORDER BY CaseOwner.UsersDepartment") or die("SELECT Error: ".mysql_error()); $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(CaseOwner.UsersDepartment)'] ." ". $row['CaseOwner.UsersDepartment'] ." types."; echo "<br />"; } ?> I have the following code. Basically I'm trying to count the amount of colours returned in the $colour variable. What I have is always returning 1, any ideas why? Code: [Select] $colour = $db->query("SELECT * FROM colours WHERE prod_id = ".$row['prod_id']." AND LENGTH(col_image_1) > 0 ORDER BY col_rank ASC LIMIT 1"); $colourcount = mysql_num_rows($colour); if($db->numrows($colour)) { $colour = $db->fetchrow($colour); } else { unset($colour); } Code: [Select] echo $colourcount; Hi, I'm trying to get a number of different keywords from many table fields, and i want to count them according to the occurrence of each keyword, so it should be like (keyword1 occurred 10 times for example ). the problem is when i use count in for loop: Code: [Select] $tags = explode("|", $row[0]); $i=1; $count = 0; for($i; $i<count($tags); $i++){ print "$count {$tags[$i]}<br />"; $count++; } it counts the occurrence of key words in each field separately from the rest (i.e. Code: [Select] 0 day 1 night 0sun 1 moon 0 clouds 1 rain ) 2 keywords in each field (some other fields got more). I want the count to be more like: Code: [Select] 1 day 2 night 3 sun 4 moon 5 clouds 6 rain thanks I wish to have a page that will display a form if there aren't already enough registrations in the database. The following it an outline of how it will be: <?php require_once "../scripts/connect_to_mysql.php"; //this works fine // Count how many records in the database (1) $sqlCommand = "SELECT * FROM teams"; (2) $sqlCommand = "SELECT COUNT (*) FROM teams"; (3) $sqlCommand = "SELECT COUNT (id) FROM teams"; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); (1) $numRegistrations = mysql_num_rows($query); //Count how many rows are returned from the query above (2) $numRegistrations = $query (3) $numRegistrations = mysql_num_rows($query); mysqli_free_result($query); ?> (Some HTML code, like DOCTYPE, head, start of body tags) <?php if($numRegistrations > 35){ echo "Sorry, registrations for this event is at it's maximum."; }else{ ?> <form blah blah blah> </form> <?php } ?> (end of body and html tag) You'll see above there is (1), (2), (3). These are the main 3 that I've been trying, and they match up the $sqlCommand to the $numRegistrations. What would be the problem with this code? I use wamp server to test, have been using it for ages. Chrome browser to test in. If I remove the database query, the rest of the page will load. With the query in there, only the HTML code up until the database query is parsed, so therefore nothing is display on the page. Please help. Thanks Denno This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=353173.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320124.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=316440.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308924.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350716.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=344992.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353645.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358188.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354997.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321772.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306094.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=308756.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351625.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348054.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347726.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312323.0 |