Avatar of tdillon80
tdillon80

asked on 

php simple function has odd behavior

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();
?>

Open in new window

<?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();
?>

Open in new window

PHP

Avatar of undefined
Last Comment
tdillon80

8/22/2022 - Mon