troubleshooting Question

php simple function has odd behavior

Avatar of tdillon80
tdillon80 asked on
PHP
12 Comments2 Solutions259 ViewsLast Modified:
I'm at my ends wit with this. This is a simple stupid function that just doesn't want to work. I simplified it incredibly for the sake of the question. The first code snippet is of a function that should produce 82, but does not. The second code snippet has the function lines (2 of them) commented out and the code runs just fine.

Please help me figure out what I'm doing wrong.

Thanks.
<?php
// THIS DOES NOT PRODUCE 82
function getReviews() {
	mysql_select_db($database_EBW_Conn, $EBW_Conn);
	$query_rsReviews = "SELECT count(r.review_id) as cnt, pp.itemname, pp.itemid, ra.percent_approved FROM product_price pp, reviews r, ratings_aggregated ra WHERE pp.entity_id = r.entity_id AND r.entity_id = ra.entity_id AND pp.itemsection = 'toys' AND pp.itemurl = 'rubber-duckie' AND r.status_id = 1 GROUP BY pp.itemname";
	$rsReviews = mysql_query($query_rsReviews, $EBW_Conn);
	$row_rsReviews = mysql_fetch_assoc($rsReviews);
	$totalRows_rsReviews = mysql_num_rows($rsReviews);
		if ($totalRows_rsReviews > 0) {
			do {
				echo "4 ";
				echo ($row_rsReviews['cnt']); // 82
			} while ($row_rsReviews = mysql_fetch_assoc($rsReviews));
		}
	mysql_free_result($rsReviews);	
}
	
getReviews();
?>
<?php
// THIS DOES PRODUCE 82
//function getReviews() {
	mysql_select_db($database_EBW_Conn, $EBW_Conn);
	$query_rsReviews = "SELECT count(r.review_id) as cnt, pp.itemname, pp.itemid, ra.percent_approved FROM product_price pp, reviews r, ratings_aggregated ra WHERE pp.entity_id = r.entity_id AND r.entity_id = ra.entity_id AND pp.itemsection = 'toys' AND pp.itemurl = 'rubber-duckie' AND r.status_id = 1 GROUP BY pp.itemname";
	$rsReviews = mysql_query($query_rsReviews, $EBW_Conn);
	$row_rsReviews = mysql_fetch_assoc($rsReviews);
	$totalRows_rsReviews = mysql_num_rows($rsReviews);
		if ($totalRows_rsReviews > 0) {
			do {
				echo "4 ";
				echo ($row_rsReviews['cnt']); // 82
			} while ($row_rsReviews = mysql_fetch_assoc($rsReviews));
		}
	mysql_free_result($rsReviews);	
//}
	
	
getReviews();
?>
ASKER CERTIFIED SOLUTION
Sandeep Kothari
Project Lead

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros