chasethemetal Posted July 16, 2011 Share Posted July 16, 2011 Hey,I have this while loop. That is displaying and counting the 5 most pages viewed. It ends up looking something like this....There are 45 http://www.sitename.com/100.php referring visitsThere are 32 http://www.sitename.com/200.php referring visitsThere are 30 http://www.sitename.com/300.php referring visitsThere are 12 http://www.sitename.com/400.php referring visitsThere are 10 http://www.sitename.com/500.php referring visitsBut what I cant figure out is how to count the loops so the echo'd result looks like....0 There are 45 http://www.sitename.com/100.php referring visits1 There are 32 http://www.sitename.com/200.php referring visits2 There are 30 http://www.sitename.com/300.php referring visits3 There are 12 http://www.sitename.com/400.php referring visits4 There are 10 http://www.sitename.com/500.php referring visitsHeres my current code, any help would be great. Thanks. while($data = mysql_fetch_array($result)){ echo "There are ". $data['COUNT(fromwhere)'] ." ". $data['fromwhere'] ." referring visits."; echo "<br />"; } Link to comment Share on other sites More sharing options...
Ingolme Posted July 16, 2011 Share Posted July 16, 2011 Add an extra variable stating at 0 and add 1 to it upon each iteration. Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 Thank you. That made sense. Heres my solution... $i = 0; while($data = mysql_fetch_array($result)){ while ($i <= 4) { $x = $i++; echo "$x There are ". $data['COUNT(fromwhere)'] ." ". $data['fromwhere'] ." referring visits."; echo "<br />"; } } Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 I spoke too soon.That actually results in this...0 There are 45 http://www.sitename.com/100.php referring visits1 There are 45 http://www.sitename.com/100.php referring visits2 There are 45 http://www.sitename.com/100.php referring visits3 There are 45 http://www.sitename.com/100.php referring visits4 There are 45 http://www.sitename.com/100.php referring visitshmmm any thoughts... Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 waaait got it!!!! $i = 0; while ($i <= 4) { while($data = mysql_fetch_array($result)){ $x = $i++; echo "$x There are ". $data['COUNT(fromwhere)'] ." ". $data['fromwhere'] ." items."; echo "<br />"; } } Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 So there is one more piece to this puzzle. If $data['fromwhere'] = "" then I don't want it to count it. In my database there are a large amounts of nothing in the fromwhere field, simply because I started filling them in late. So I was wondering if there was a way exclude counting if the fromwhere field is empty. Thanks Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 This is my current Query. I cant figure out where to but the NOT LIKE '' $query = "SELECT fromwhere, COUNT(fromwhere) FROM uniqueVisit GROUP BY fromwhere ORDER BY COUNT(fromwhere) DESC LIMIT 5"; Link to comment Share on other sites More sharing options...
jeffman Posted July 16, 2011 Share Posted July 16, 2011 Try. . . FROM uniqueVisit WHERE fromwhere <> '' GROUP BY fromwhere . . .That's a pair of single quotes, BTW Link to comment Share on other sites More sharing options...
chasethemetal Posted July 16, 2011 Author Share Posted July 16, 2011 Thanks that did the trick! This issue is solved. Over n out. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.