Re: PHP and MySQL SELECT COUNT (*)
| From: | Vinny Gullotta | Date: | Wed, 17 Sep 2008 20:20:16 +0000 |
| Subject: | Re: PHP and MySQL SELECT COUNT (*) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280403@lists.php.net to get a copy of this message | ||
""Dan Joseph"" <dmjoseph@gmail.com> wrote in message news:a20394490809171258i76089f43gcacc29791f62ea13@mail.gmail.com...
On Wed, Sep 17, 2008 at 2:17 PM, Vinny Gullotta <vgullotta@intermedia.net>wrote:yeah, I've tried that combination before, but just for grins I tried it again, and same result. It displays the counts but not the servernames.What I want to do is find the top 10 servers where the column steps = iisreset. The following code works great except that the page is not displaying the servername in the 'Server Name' column of my results (nothing appears, the column is just blank). servername and steps are the important columns in the database table. $_POST[time1] and $_POST[time2] come from a form submitted. When I copy and paste the entire select statement into the SQL tab in phpmyadmin (and replace the time variables with actual times corresponding to the timestamp column), it displays the correct results including servername. Everything works in the php page's results except for the servername. I feel like it's right in front of my face and that's why I can't see it lol. Any help would be greatly appreciated. Thanks in advance =) My code... $query = "SELECT servername, COUNT(steps) FROM monitoring WHERE steps LIKE 'iisreset' AND timestamp <= '$_POST[time2]' AND timestamp >= '$_POST[time1]' GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); # display column titles echo "<center><table class='table'><tr>"; echo "<td class='tableHeader'><center><small><b>Count</b></small></td>"; echo "<td class='tableHeader'><center><small><b>Server Name</b></small></td>"; echo "</tr>"; #display results while($i = mysql_fetch_row($result)) { echo "<tr><td><small><center>", $i[COUNT('steps')], "</center></small></td>"; echo "<td><small><center>", $i[servername] ,"</center></small></td></tr>"; } echo "</table></center><br>"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php$i[servername] Try: $i['servername'] notice the ' and ' around the name. I've heard you can do w/o those, but I've had issues in the past where it didn't work. ITs also good practice to use 'em. -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."