Jump to content

Archived

This topic is now archived and is closed to further replies.

curtis_b

DISTINCT query works in phpmyadmin, not in script

Recommended Posts

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_USERS

into 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 resource

the 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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
fixed.


all i had to do was add my db name in the statement:

SELECT DISTINCT addby FROM _ypc.T_USERS

phpmyadmin already knows what db you are working with so it wasn't necessary in that prog.

thanks

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.