Very complicated SQL Query with 2 nested - not working

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
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Very complicated SQL Query with 2 nested - not working

Post by requinix »

VladSun wrote:You don't assign value to $result anywhere in your code ...
Yeah, I just now noticed that :banghead: Not even present in the original code.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Very complicated SQL Query with 2 nested - not working

Post by simonmlewis »

Ok.
I now have this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1
Based on this code:

Code: Select all

sqlconn=@mysql_connect("localhost","u","p");
$rs=@mysql_select_db("db",$sqlconn);
$result = mysql_query("SELECT * FROM matternudge WHERE matterno = '$matterno'");
mysql_query($result) or die(mysql_error());
if (mysql_num_rows($result)==0) 
  { 
    mysql_query("INSERT INTO matternudge (matterno, nudgedate) VALUES ('$matterno', '$nudgedate')");
    }
else
  {
  while ($row = mysql_fetch_object($result))
      {
        mysql_query ("UPDATE matternudge SET nudgedate = '$nudgedate' WHERE matterno = '$matterno'");
        }
  }
 
    mysql_free_result($result);
    mysql_close($sqlconn); 
 
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Very complicated SQL Query with 2 nested - not working

Post by VladSun »

Code: Select all

$result = mysql_query("SELECT * FROM matternudge WHERE matterno = '$matterno'");
mysql_query($result) or die(mysql_error());
:?
http://php.net/mysql_query
There are 10 types of people in this world, those who understand binary and those who don't
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Very complicated SQL Query with 2 nested - not working

Post by simonmlewis »

.... yes...?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Very complicated SQL Query with 2 nested - not working

Post by VladSun »

simonmlewis wrote:.... yes...?
Read it!
Especially the examples section.
There are 10 types of people in this world, those who understand binary and those who don't
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Very complicated SQL Query with 2 nested - not working

Post by simonmlewis »

That is one very long page to read and find one small solution.

I have used this code method for a very long time, and in fact, further up the page this code is used for a different purpose, and it works!

So your blunt "read it" comment holds no strength here for me.
The previous supportive person has been very help to date, and I would like to thank them.

Regards, Simon.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Very complicated SQL Query with 2 nested - not working

Post by VladSun »

I already knew in your previous thread ( viewtopic.php?f=1&t=93759 ) that you would continue asking for copy-paste code snippets. That's why I gave you those answers there and I'll continue to do it in this thread and all of your future threads until you start reading the manuals, thinking and stop copy-pasting blindly and asking for ready to use solutions.
When it happens you'll find out that I have been the most helpful person ;)

"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

EDIT:
...That is one very long page to read...
Really?!? Pressing PgDn key twice is a "long page" ???
There are 10 types of people in this world, those who understand binary and those who don't
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Very complicated SQL Query with 2 nested - not working

Post by simonmlewis »

Most helpful.
I'll ask you the way from London to Edinburgh, and you are the sort of person to say, "that's the way to the M25, follow that....".

Those who tend to use this forum have done just about all they can to find a solution, so need guidance and an answer, to save hours more work - from someone who knows the answer.

Being "helpful" is not giving me the sign to the M25, it's giving me the full route, otherwise I just keep looking and keep posting on here - wasting everyone's time.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Very complicated SQL Query with 2 nested - not working

Post by Eran »

No, being helpful is explaining to you how to read your map instead of having you memorize the route. Vladsun was trying to help you understand what you did wrong instead of simply how to fix it.

It's too bad that you didn't take him up on his advice. Can't say it's too surprising though, as you say most people come here for simple quick fixes and not to learn.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Very complicated SQL Query with 2 nested - not working

Post by simonmlewis »

You learn from fixes, especially when they are explained.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Very complicated SQL Query with 2 nested - not working

Post by Eran »

Reading this thread, I'd have to say unfortunately that it seems you haven't learned much. But, hey what do I know, it's not like I do this for a living..
Post Reply