Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 15th, 2004, 5:24 AM   #1
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/h2zdesig/public_html/chat.php on line 39

*its impossible to search Google for this cause it appears so often*

How do I fix that? the line looks like this
function getMessages() {
  $rs = mysql_query( "SELECT * FROM MINICHAT ORDER BY NB" );

  $ret = Array();
  while ( $msg = mysql_fetch_array( '$rs' )) {
   $ret[] = date('h:m', $msg['ITSTIME'] )." ".$msg['LOGIN']." >".$msg['MESSAGE'];
  }

  return $ret;
}
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Old Oct 15th, 2004, 5:48 AM   #2
Ade
Hobbyist Programmer
 
Ade's Avatar
 
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0 Ade is an unknown quantity at this point
Just looked at some of my code and I don't have the ' either side of the variable.

like


mysql_fetch_array($result) instead of mysql_fetch_array( ' $result ' )

?

Might not make a difference but it's all I can see between your code and one that works for me.
__________________
Don't wound what you can't kill
Ade is offline   Reply With Quote
Old Oct 15th, 2004, 10:41 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
For sure that's the problem. a resource result doesn't need quotes.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 17th, 2004, 3:42 PM   #4
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
no beans, I've tried every variation, adn it still doesn't like it

function getMessages() {
  $rs = mysql_query("SELECT * FROM MINICHAT ORDER BY NB");

  $ret = Array();
  $msg = mysql_fetch_array($rs);
  while ( $msg ) {
   $ret[] = date('h:m', $msg['ITSTIME'] )." ".$msg['LOGIN']." >".$msg['MESSAGE'];
  }

  return $ret;
}
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Old Oct 17th, 2004, 4:28 PM   #5
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
I got it, by adding
if (!$rs) {
  die('Invalid query: ' . mysql_error());
}
i found were it was exactly erring out, and fixed it
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Old Oct 18th, 2004, 10:40 AM   #6
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
So the Problem was with your SQL then? Looks like you were missing a ; now that i think about it. Then again, i am a postgresql user ;-) I don't know that much about how mysql querys work.

anyways, glad to hear that you got it working.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 19th, 2004, 4:14 PM   #7
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Quote:
Originally posted by Pizentios@Oct 18 2004, 02:40 PM
So the Problem was with your SQL then? Looks like you were missing a ; now that i think about it. Then again, i am a postgresql user ;-) I don't know that much about how mysql querys work.

anyways, glad to hear that you got it working.
Actually with PHP, Perl, and almost every other database binding interface you never place the trailing ";" since you can only execute one query at a time anyway. And for some servers, this means you do not need the trailing '\g'

This includes Postgre and the DBI:: module in perl.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Oct 19th, 2004, 4:22 PM   #8
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
hmmm, i put it into my querys i think....never really put much thought to it. What happens if i leave em in?
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 19th, 2004, 5:08 PM   #9
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
You can use them but they are not nessecary.

It's kinda nice just to do it though because most commands/statements end in a ;.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Oct 27th, 2004, 10:27 AM   #10
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
You have to send the mysql resource as an argument to the function so that the variable can be used inside of the function.

When you open the connection with mysql_connect assign the connection to a variable. Although it will be assumed in all other parts of your code, you will need this when calling your function.

function getMessages($resource) {
 $rs = mysql_query( "SELECT * FROM MINICHAT ORDER BY NB", $resource );

 $ret = Array();
 $count = 0;

 while ( $msg = mysql_fetch_assoc($rs))
   $ret[$count++] = date('h:m', $msg['ITSTIME'] )." ".$msg['LOGIN']." >".$msg['MESSAGE'];

 return $ret;
}

Im not 100% on that so you could also try...

function getMessages() {
 $rs = mysql_query( "SELECT * FROM MINICHAT ORDER BY NB");

 $ret = Array();
 $count = 0;

 while ( $msg = mysql_fetch_assoc($rs))
   $ret[$count++] = date('h:m', $msg['ITSTIME'] )." ".$msg['LOGIN']." >".$msg['MESSAGE'];

 return $ret;
}

And that could just work.

Hope ive helped.
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC