Help - Search - Members - Calendar
Full Version: MySQL - Does anyone know the anwer...
Get Paid Forum - Get Paid Discussion > Webmaster's Corner > Advertising Section related to Running a website > Script Exchange > For Sale Archive
BonusEmails
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /.......edited for my peace of mind lol...../function.php on line 17

Here's the bit it's from - I've marked the line number:

QUOTE
15     function getResult($query) {
16         $result = mysql_query($query);
17         $row = mysql_fetch_array($result);
18         while($row!=NULL) {


If anyone has any ideas, but needs more to be certain, I can let you have the full file, just don't want to fill the page (makes a change for me lol).

Thanks in advance aa.gif Yes, I know, I am demonstrating pure stupidity!!
Ca$hMaN
i think you messed up some words maybe ?
$row and $query maybe ...
Gilby
Most likely the query was invalid and caused errors. You'll get your answer by executing "echo mysql_error()" after the query is made.
petcalent
No idea about mysql... but is clear
you have to replace $result in line 17

17 $row = mysql_fetch_array($result);

for another magic word or words that works ad.gif
freeandeasy
QUOTE (BonusEmails @ Feb 26 2003, 04:45 PM)
Yes, I know, I am demonstrating pure stupidity!!

Coulda fooled me...it's totally over my head. You seem intelligent about it to me.
SupaDupaFly
Nothing wrong with those lines. Make sure you are connected to database and you have a correct SQL statement. Most likely you are not connected to database.

You should add this before line 17. But if you have no idea about PHP dont cause you might put {} in wrong places.

if(!mysql_num_rows($result)) //check if there are records
echo "Huk! No records in database! Oh noS!!!";
else{

//everything after line 17 (inc line 17) till the function ends.
}

So you dont do line 17 if there are no records in database..
ReDucTor
I thought I replied to this one, guess I mustn't have, don't tell me I posted it in the wrong thread..

it doesn't have the result, because the query has fault, it has returned FALSE because PHP's mysql_query function return FALSE if the query failed.

or else it could just be true, which it only returns for update, insert, etc when its successful..

Change it to:

CODE
    function getResult($query) {
        $result = mysql_query($query) or die("Error in ".$query.": ".mysql_error());
        $row = mysql_fetch_array($result);
        while($row!=NULL) {


then post here what that gets you, which will then tell us the required information to help you over come your problem...
BonusEmails
QUOTE (freeandeasy @ Feb 27 2003, 01:59 AM)
QUOTE (BonusEmails @ Feb 26 2003, 04:45 PM)
Yes, I know, I am demonstrating pure stupidity!!

Coulda fooled me...it's totally over my head. You seem intelligent about it to me.

LMAO!! Don't you try to creep just cos you know it's your fault - getting me started messing with scripts again lol ac.gif hehe only kidding aa.gif Though it is your fault lol ae.gif
BonusEmails
Thanks so much guys aa.gif

Ok, lets try some of these aa.gif

SupaDupaFly... Did yours and it came back saying the same but on line 23 (that line 17 had moved to) plus the same for the mysql_num_rows line. But as you say, I could have put the } in the wrong place, I probably did lol.

ReDucTor ... Yours gave me :

Error in select count(distinct date) as count from is_daycount: No Database Selected

So basically, I'm not connected to the database ah.gif I've checked and where it has the database name it is entered correctly as with all the other info as far as I know). Is there something in these two lines that affects it?

$db_link = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name, $db_link);

basically should I give up on this one? lol

Thanks again to everyone aa.gif
freeandeasy
QUOTE (BonusEmails @ Feb 27 2003, 10:17 AM)
QUOTE (freeandeasy @ Feb 27 2003, 01:59 AM)
QUOTE (BonusEmails @ Feb 26 2003, 04:45 PM)
Yes, I know, I am demonstrating pure stupidity!!

Coulda fooled me...it's totally over my head. You seem intelligent about it to me.

LMAO!! Don't you try to creep just cos you know it's your fault - getting me started messing with scripts again lol ac.gif hehe only kidding aa.gif Though it is your fault lol ae.gif

haha ac.gif
BonusEmails
Got it sorted! Thanks so much guys.

I deleted everything and started again, and it's working :-) I probably did something the first time that messed it up - I'm good at that! ao.gif lol

I really am grateful to you guys tho for helping (except Cathy whose fault it is LOL ac.gif ).

When people try to help like this it really makes me think that its worthwhile how nice I am to my members hehe.
top-designing
You have a simply error, you have forgett to insert the mysql connection string.

For example

$row=mysql_querry($sql, $Dbconnection->Connection);
Because you must specifiy a conn function
top-designing
Also do not use this kind of syntax
$row!=NULL also specify the format of how you would like the array to be indexed,
so the mysql_fecth_array must be like:
$row=mysql_fetch_array($result,MYSQL_ASSOC) and u will access the elements with $row['user']
or
$row=mysql_fetch_array($result,MYSQL_NUM) and u will access the elements with $row[1]
It is not a good idea to use defaults when u are programming.
it is not necessary, instead try to use this one
while ($row=mysql_fetch_array())
{
//Here you are able then to access
}
If u will need more just send me a PM
top-designing
Try to verify if the dbusername and password are ok and also check the dblink (i think that here is the problem).
freeandeasy
ao.gif ak.gif
ReDucTor
QUOTE (top-designing @ Mar 2 2003, 01:37 PM)
Also do not use this kind of syntax
$row!=NULL also specify the format of how you would like the array to be indexed,
so the mysql_fecth_array must be like:
$row=mysql_fetch_array($result,MYSQL_ASSOC) and u will access the elements with $row['user']
or
$row=mysql_fetch_array($result,MYSQL_NUM) and u will access the elements with $row[1]
It is not a good idea to use defaults when u are programming.
it is not necessary, instead try to use this one
while ($row=mysql_fetch_array())
{
//Here you are able then to access
}
If u will need more just send me a PM

Whats wrong with it? mysql_fetch_array returns FALSE on no rows, with type conversion in PHP that will evaluate false on no rows. Its not using !== So it wil be fine, because types will be changed to match.

Actually, its easier to select it with out the type if more then one person is using it, some people prefer indexes(only good when selecting single fields, not whole rows), and others prefer associative arrays, so there for using mysql_fetch_array it will get both index and assoc, instead of specifying them.

By the looks of the query that she/he was doing it was a single one, so there for using a while() would slow it down(altough its not noticable), and be useless.

CODE
if($row=mysql_fetch_assoc($result))
{

}


would be better for single queries, but if there is a break or return needed, just use

CODE
$row=mysql_fetch_assoc($result) or return;


When connecting its always best to check if it did connect..
BonusEmails
QUOTE (freeandeasy @ Mar 2 2003, 07:01 AM)
ao.gif ak.gif

LOL ditto!!

Well guys, have to admit you did lose me a bit there lol.

The scripts are working without modifications, I just need to get it to link to the database correctly now. Only certain parts that should register into the database are, but that's something I can work out given a brain LOL - I'll get there, now the scripts aren't rejecting me aa.gif

Thank you so much for all your help, if you hadn't given me the tips on things to try, I'd have never worked out what was going on aa.gif
top-designing
ReDucTor is about the style and the level.
Our friend is new into this world and is better for him to try to create a style and after that to do other things.

Do not tell me that from the beginning you have used "or return".
Sometimes a single line is not easy to understand or to debug.

Best Regards
top-designing
Also i think that if you will not use MYSQL_ASSOC or MYSQ_NUM, PHP will lose some little, very little time to see how you are indexing the array.

And to lose time is not so good for your script and for your style.
ReDucTor
ad.gif ad.gif ad.gif I'm Wierd, My style of programming and methods at times are Unique and Benefical, but Confusing, and can drive you stark raving mad if you stare at it for too long ad.gif ad.gif ad.gif

ad.gif ad.gif ad.gif
top-designing
ab.gif ab.gif ab.gif
I'm a little alien in NY :ph34r: :ph34r: :ph34r:
ab.gif ab.gif ab.gif
ReDucTor
QUOTE (top-designing @ Mar 4 2003, 01:00 PM)
Also i think that if you will not use MYSQL_ASSOC or MYSQ_NUM, PHP will lose some little, very little time to see how you are indexing the array.

And to lose time is not so good for your script and for your style.

PHP will use MYSQL_BOTH which will when adding it in do the index, then the assoc, or assoc then the index, been a while from looking, this will slow it down for more to look over, but this time is irrelivent unless you are yahoo or some very high traffic site or do hundreds of useless queries aa.gif
top-designing
I really do not understand
I saw that you like ASM, but i did not expect from such a guy (like you) to admit the idea to lose time, thats why i have told you "is about style".
ah.gif
top-designing
If you have a MSN address search for me: top_designing@hotmail.com we can talk about a lot of things.
Lets end this discussion because the subject of the topic is not our programming skills.
ReDucTor
yes, style is a good thing

use
CODE
while($row=mysql_fetch_assoc($q)){ .. }


not
CODE
for($i=0;$i<mysql_num_rows($q);$i++){ $row=mysql_fetch_assoc($q); ... }
top-designing
You have a big LOL from me
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.