curtis_b Posted June 14, 2006 Share Posted June 14, 2006 I have a query that gets only distinct values from one column in a mysql table. I have my php script set to print out the actual sql that is being sent by the script for debugging. When I copy and paste the output:SELECT DISTINCT addby FROM T_USERSinto the phpmyadmin sql sender, it returns exactly what I need. However in the php script I get an error:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resourcethe line it references is:while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){and yes, $result is the correct variable for the mysql_query statement in my script.could it be that fetch_array is the incorrect method for a single column result set? Your help is greatly appreciated!Curt Quote Link to comment https://forums.phpfreaks.com/topic/12033-distinct-query-works-in-phpmyadmin-not-in-script/ Share on other sites More sharing options...
poirot Posted June 14, 2006 Share Posted June 14, 2006 Probably you are not doing it correctly.Remember, $result mustn't be the query itself, but the [b]result resource[/b].Read:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95441\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95441[/a][a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95443\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95443[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12033-distinct-query-works-in-phpmyadmin-not-in-script/#findComment-45755 Share on other sites More sharing options...
curtis_b Posted June 15, 2006 Author Share Posted June 15, 2006 fixed. all i had to do was add my db name in the statement: SELECT DISTINCT addby FROM _ypc.T_USERSphpmyadmin already knows what db you are working with so it wasn't necessary in that prog. thanks Quote Link to comment https://forums.phpfreaks.com/topic/12033-distinct-query-works-in-phpmyadmin-not-in-script/#findComment-45761 Share on other sites More sharing options...
.josh Posted June 15, 2006 Share Posted June 15, 2006 or you could like, follow up your mysql_connect with mysql_select_db('..'); Quote Link to comment https://forums.phpfreaks.com/topic/12033-distinct-query-works-in-phpmyadmin-not-in-script/#findComment-45796 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.