Jump to content


Photo

DISTINCT query works in phpmyadmin, not in script


  • Please log in to reply
3 replies to this topic

#1 curtis_b

curtis_b
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 14 June 2006 - 11:48 PM

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



#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 11:51 PM

Probably you are not doing it correctly.
Remember, $result mustn't be the query itself, but the result resource.

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]
~ D Kuang

#3 curtis_b

curtis_b
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 15 June 2006 - 12:04 AM

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

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 15 June 2006 - 04:18 AM

or you could like, follow up your mysql_connect with mysql_select_db('..');

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users