Page 1 of 1

Need help with PHP/MySQL code

Posted: Thu Feb 19, 2009 10:08 am
by kdidymus
Folks.

I'm quite proud of the fact for the past 6 months I've gone away and used all of the knowledge gleaned from you all to create a pretty good website. You'll find the old version at http://www.didymus.org.uk

I'm now working on a more graphical version. The PHP coding is going well and you'll find a working (but not fully working version at http://www.didymus.org.uk/new/tree/disp ... ?urn=11164

So. On to my question. And I'm really hoping someone can answer it as it will save me literally hours of manual scanning.

I need to build some PHP code that will access my MySQL database and return any instances of the following:
Where $spouse1urn is blank AND $spouse1child1urn is not blank
and
Where $spouse2urn is blank AND $spouse2child1urn is not blank
Anybody got any ideas? Other than go and buy yet another PHP primer of course!

Thanks very much in advance for your help.

KD.

Re: Need help with PHP/MySQL code

Posted: Thu Feb 19, 2009 1:25 pm
by greyhoundcode
As far as the SQL element goes, would something like this do the trick?

Code: Select all

SELECT * FROM `table` WHERE `field_1` = NULL AND `field_2` != NULL;

Re: Need help with PHP/MySQL code

Posted: Thu Feb 19, 2009 3:57 pm
by kdidymus
Yes it would. Was the ! a typo or does that need to be there?

Thanks for that. I'm not an expert at MySQL.

KD.

Re: Need help with PHP/MySQL code

Posted: Thu Feb 19, 2009 4:38 pm
by watson516
kdidymus wrote:Yes it would. Was the ! a typo or does that need to be there?

Thanks for that. I'm not an expert at MySQL.

KD.
The ! is used as NOT. != is NOT equal

If Im not mistaken, you could do this:

Code: Select all

SELECT * FROM TABLE WHERE (something = NULL AND somethingelse != NULL) OR (something != NULL AND somethingelse = NULL)
That should return both of your needed queries.

Re: Need help with PHP/MySQL code

Posted: Thu Feb 19, 2009 11:22 pm
by kdidymus
What can I say apart from thank you all yet again?!

I shall go forth and run that enquiry!

KD.