dropfaith Posted September 11, 2008 Share Posted September 11, 2008 so hopefully this is easy but i cant for the life of my fiqure it out i want to display the number of total images on top and then per set display the amount of images listed under a field named Cat in the gallery table http://dropfaithproductions.com/test/gallery.php right now it gets the total image count but i dont now how to limit it to display from a cat im assuming its a simple where clause but no idea how to manage it on the num rows in the loop Php <?php // includes include("template/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $sql = "SELECT * FROM gallery"; $result = mysql_query($sql); $query = "SELECT * FROM galleryname"; $qresult = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if records present if (mysql_num_rows($qresult) > 0) { // iterate through resultset // print article titles while($row = mysql_fetch_object($qresult)) { ?> Html <h2>Total Images Online <? echo mysql_num_rows($result);?></h2> <div align="left"> <div class="header" style="width:100%;background-color:#333;color:#FF1493;"> <h3><a href="photoset.php?Cat=<? echo $row->Gallery; ?>"><? echo $row->Gallery; ?></a></h3> </div> <div class="image" style="width:150px;float:left;"> <a href="photoset.php?Cat=<? echo $row->Gallery; ?>"> <img style="height:145px;width:145px" src="http://www.dropfaithproductions.com/test/images/<? echo $row->uploaded; ?>"> </a> </div> <div class="text" style="float:right:width:500px;"><? echo $row->About; ?><br /> <span style="color:#FF1493;font-wieght:bold;">Images in Set <? echo mysql_num_rows($result);?></span> </div> </div><div style="clear:both;"> </div> Link to comment https://forums.phpfreaks.com/topic/123839-mysql_num_rows-where/ Share on other sites More sharing options...
tmbrown Posted September 11, 2008 Share Posted September 11, 2008 <?php $result = mysql_query("SELECT * FROM {table} WHERE {field} ='{valuer}'"); $count = mysql_num_rows($result); echo($count); ?> or you could do this <?php $result = mysql_query("SELECT * FROM {table} WHERE {field} ='{valuer}'"); $arr = array(); while($row = mysql_fetch_assoc($result)){ $arr[] = $row; } if(is_array($arr)){ $count = count($arr); echo($count); } ?> Link to comment https://forums.phpfreaks.com/topic/123839-mysql_num_rows-where/#findComment-639398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.