otuatail Posted June 8, 2008 Share Posted June 8, 2008 cant get simple query to return anything. The querry when used in mysql via phpmyadmin returns 276 $sqlhits = "select count(EventID) FROM EventLog AS Count WHERE Hit = 'Y'"; $rsHits = mysql_query($sqlhits); $Item = mysql_fetch_array($rsHits); echo $Item['Count']; retuns blank Quote Link to comment Share on other sites More sharing options...
otuatail Posted June 8, 2008 Author Share Posted June 8, 2008 This does work $Item[0]; This dosn't $Item['Count']; Quote Link to comment Share on other sites More sharing options...
Loldongs Posted June 8, 2008 Share Posted June 8, 2008 do print_r($Item); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 8, 2008 Share Posted June 8, 2008 That would be because there isn't a row in your result set called Count. You're using an alias on the table name rather than the selected row. $sqlhits = "select count(EventID) as Count FROM EventLog WHERE Hit = 'Y'"; Quote Link to comment Share on other sites More sharing options...
otuatail Posted June 9, 2008 Author Share Posted June 9, 2008 If I use an Alias then that should be returned. It works in sql server also if I run the query in Mysql Admin it shows the result under the Alias name. You should be able to use an alias for any columb name. Quote Link to comment Share on other sites More sharing options...
craygo Posted June 9, 2008 Share Posted June 9, 2008 you can use an alias for any column name but depends where you put it. you put Count in your FROM clause so you are giving the alias to your table not your column. If you had 2 tables with the same column name your query would fail. In phpmyadmin it should actually show count(Eventid) so if you wanted to return it in php it would be $Item['count(Eventid)'] All aliases for column names should be in the SELECT clause. Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.