[SOLVED] Shouldnt this function work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

try:

Code: Select all

mysql_fetch_assoc($resultd);
System_Failure
Forum Newbie
Posts: 18
Joined: Thu Aug 05, 2004 11:14 pm

Post by System_Failure »

Joe wrote:try:

Code: Select all

mysql_fetch_assoc($resultd);
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /path/functions.php on line 184
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$resultd = mysql_query($queryd) or die(mysql_error());
If you use that in both instances (your 2 queries) it should tell you why it's failing.
System_Failure
Forum Newbie
Posts: 18
Joined: Thu Aug 05, 2004 11:14 pm

Post by System_Failure »

Surprisingly, its saying "No Database Selected" as the error message! But I did select the database in the header
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Also add ... or die(mysql_error()); to your mysql_connect() and mysql_select_db() calls just to be sure they are working ok.
What's weird is that previously you were getting the results from the query ok but now you're not .. something must have changed during that time :o
System_Failure
Forum Newbie
Posts: 18
Joined: Thu Aug 05, 2004 11:14 pm

Post by System_Failure »

well, the rest of the page can connect to the database and retrive data, but just that function seems to be unable to detect the database :(
System_Failure
Forum Newbie
Posts: 18
Joined: Thu Aug 05, 2004 11:14 pm

Post by System_Failure »

Solved.....I had to connect again in the function, and then close the connection af the end of the function :(

I can not thank you all enough for helping...your help was really really appreciated :). I've spent two days on this, and finally I can move on and complete the project :p

Edit: One problem though, main connection set in the header is in the variable $link, and the quick one on functions.php for the function is called $link2. Now, I close the $link2 connection at the end of functions.php, and I close my main one in the footer.php file. Now I am getting this error :

Code: Select all

Warning: mysql_close(): 6 is not a valid MySQL-Link resource in /path/footer.php on line 14
Line 14 is mysql_close($link);
System_Failure
Forum Newbie
Posts: 18
Joined: Thu Aug 05, 2004 11:14 pm

Post by System_Failure »

kinda did a temporary fix to that by disconnecting $link just before echoing the function, and reconnecting $link again just after echoing the function.
Post Reply