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 Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/ 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']; Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/#findComment-560402 Share on other sites More sharing options...
Loldongs Posted June 8, 2008 Share Posted June 8, 2008 do print_r($Item); Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/#findComment-560408 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'"; Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/#findComment-560413 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. Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/#findComment-561091 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 Link to comment https://forums.phpfreaks.com/topic/109252-stupid-query/#findComment-561096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.