![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2004
Posts: 32
Rep Power: 0
![]() |
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;
}
__________________
<CENTER><span style='font-size:17pt;line-height:100%'>My Homepage</span></CENTER> |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2004
Posts: 32
Rep Power: 0
![]() |
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;
}
__________________
<CENTER><span style='font-size:17pt;line-height:100%'>My Homepage</span></CENTER> |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Oct 2004
Posts: 32
Rep Power: 0
![]() |
I got it, by adding
if (!$rs) {
die('Invalid query: ' . mysql_error());
}![]()
__________________
<CENTER><span style='font-size:17pt;line-height:100%'>My Homepage</span></CENTER> |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#7 | |
|
Expert Programmer
|
Quote:
This includes Postgre and the DBI:: module in perl.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
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.
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|