yeochinh Posted December 16, 2009 Share Posted December 16, 2009 Hi guys, Im currently having problems with this code: $query = ("SELECT COUNT(faculty.FacultyID),department.departmentname,building.buildingname FROM faculty JOIN department JOIN building WHERE faculty.departmentID = department.departmentID && department.buildingID = building.buildingID GROUP BY departmentname"); $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Total Number of Faculty :".$row[0]. " <br>"; echo "Department Name : ".$row[1] ." <br>"; echo "Building Location : ".$row[2]." <br><br>"; } Although it loops 11 times (which is the number of items), it doesnt display the content of each row. Any advice? Thanks Thanks Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/ Share on other sites More sharing options...
KevinM1 Posted December 16, 2009 Share Posted December 16, 2009 When using the MYSQL_ASSOC flag, you need to reference column data by their column name rather than column number, i.e.: $row['columnName'] Where 'columnName' is the name of the MySQL table column your data resides in. More info - mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/#findComment-978659 Share on other sites More sharing options...
yeochinh Posted December 16, 2009 Author Share Posted December 16, 2009 Hi, I've tried doing what you said. but it still didn't show any result. This is the code that I used: $query = ("SELECT COUNT(faculty.FacultyID),department.departmentname,building.buildingname FROM faculty JOIN department JOIN building WHERE faculty.departmentID = department.departmentID && department.buildingID = building.buildingID GROUP BY departmentname"); $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Total Number of Faculty :".$row['faculty.facultyID']. " <br>"; echo "Department Name : ".$row['department.departmentName'] ." <br>"; echo "Building Location : ".$row['building.buildingName']." <br><br>"; } Advice please. Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/#findComment-978661 Share on other sites More sharing options...
wildteen88 Posted December 16, 2009 Share Posted December 16, 2009 Your code should be echo "Total Number of Faculty :".$row['COUNT(faculty.FacultyID)']. " <br>"; echo "Department Name : ".$row['departmentName'] ." <br>"; echo "Building Location : ".$row['buildingName']." <br><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/#findComment-978665 Share on other sites More sharing options...
yeochinh Posted December 16, 2009 Author Share Posted December 16, 2009 I've solved it! I used MYSQL_NUM $query = ("SELECT COUNT(faculty.FacultyID),department.departmentname,building.buildingname FROM faculty JOIN department JOIN building WHERE faculty.departmentID = department.departmentID && department.buildingID = building.buildingID GROUP BY departmentname"); $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "Total Number of Faculty :".$row[0]. " <br>"; echo "Department Name : ".$row[1] ." <br>"; echo "Building Location : ".$row[2]." <br><br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/#findComment-978672 Share on other sites More sharing options...
yeochinh Posted December 16, 2009 Author Share Posted December 16, 2009 Thanks to everyone who helped Quote Link to comment https://forums.phpfreaks.com/topic/185379-php-not-displaying-items/#findComment-978673 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.