Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql_fetch_assoc error
Old 05-06-2005, 09:27 AM mysql_fetch_assoc error
Junior Talker

Posts: 2
Trades: 0
$result1=mysql_query("SELECT * FROM members WHERE 1");
if (!$result1) {
echo "here 1";
exit;
}
if (mysql_num_rows($result1) == 0) {
echo "Here2";
exit;
}
while ($row = mysql_fetch_assoc($result1) or die("Here 3")) {
............
some code here
............
mysql_free_result($result1);
}

the page stop loading and it returns Here 3.

When i go in my database i check which users have been updated and all users exept the last one are updated.

heres the error i get on my page.

Warning: mysql_free_result(): 965 is not a valid MySQL result resource in /home/asdf/public_html/asdf.php on line 110

Help me please >_<

Thanks.
XeqtR is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-06-2005, 09:35 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
XeqtR,

Don't call mysql_free_result() inside your loop. This will free the mysql resource on the first iteration. It should be AFTER your while loop. Also, I don't recommend putting an "or die" clause on a while loop. Eventually all the records will be iterated and you're going to hit that die clause -- die clauses are intended for error detection.

But to answer your question, if you are calling mysql_free_result() inside your while loop, then you are sabotaging any subsequent iterations because it will fail.

What I don't understand is how it is properly updating ANY records beyond the first one.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 05-06-2005, 01:40 PM
Junior Talker

Posts: 2
Trades: 0
K so i removed the die and the free result and now i have an infinite loop.
XeqtR is offline
Reply With Quote
View Public Profile
 
Old 05-06-2005, 07:36 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Unless there are an infinite number of entries in your db, the while should go through each row in turn and then evaluate false on the last one.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to mysql_fetch_assoc error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.78941 seconds with 12 queries