Jump to content

Resetting The Array


Hooch
 Share

Recommended Posts

Hey all.Is there a way to reset

$num['COUNT(field1)']

back to zero after each echo?It counts the very 1st result and just repeats.

<?PHP$db_query = mysql_query("SELECT `field1` FROM `table1` ORDER BY `field1` ASC");while($r = mysql_fetch_array($db_query)){	$db_query2  = mysql_query("SELECT `field1`, COUNT(field1) FROM `table2`");	$num		= mysql_fetch_array($db_query2);	echo '<li><a href="admin_gallery_new.php?edit=1&cat=' . $r['field1'] . '">' . $r['field1'] . '(' . $num['COUNT(field1)'] . ')</a></li>';}?>

Thank you for any help.

Link to comment
Share on other sites

It's doing exactly what you're telling it to, you keep running the exact same query in the loop, so it's going to keep printing the exact same answer. Should you have a WHERE clause on your inner query so that it's not running the same thing every time through the loop? Or should you be looping through the results of the second query instead of always printing the first record?

Link to comment
Share on other sites

Thanks Guy!!Very simple fix.

			<?PHP			$db_query = mysql_query("SELECT `field1` FROM `table1` ORDER BY `field1` ASC");			while($r = mysql_fetch_array($db_query))			{				$cat   = $r['field1'];				$query = mysql_query("SELECT `field1`, COUNT(field1) FROM `photos` WHERE `table2` = '$cat'");				$num   = mysql_fetch_array($query);				echo '<li><a href="admin_gallery_new.php?edit=1&cat=' . $cat  . '">' . $cat  . '(' . $num['COUNT(field1)'] . ')</a></li>';			}			?>

:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...