Need help with PHP/MySQL code

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

Post Reply
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Need help with PHP/MySQL code

Post 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.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Need help with PHP/MySQL code

Post 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;
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Re: Need help with PHP/MySQL code

Post 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.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Need help with PHP/MySQL code

Post 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.
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Re: Need help with PHP/MySQL code

Post by kdidymus »

What can I say apart from thank you all yet again?!

I shall go forth and run that enquiry!

KD.
Post Reply