Okay, let me try and explain this in under one million words?! :rolleyes:
I have a PHP script which logs whenever someone visits a Member's Profile.
The visitor_log table looks like this...
And my member table looks like this...
Here is the problem...
If a Non-Member (i.e. No MemberID) visits a Member's Profile, I still want/need something to stick in "visitor_id".
Originally I was going to stick a NULL in there, but then I realized that won't work since it part of my Composite Primary Key.
So then I decided to just insert a "0" in there.
Problem is that then I would have to create a "dummy" Member profile for Anonymous Visitors. (Think "Referential Integrity"!!)
Also, since the field is MEDIUMINT UNSIGNED, I can't use "0"?!
And I don't want to change the Data-Type for several reasons.
I *really* wanted to insert a NULL or "0" in there to make Anonymous Visitors stand out, but I don't see an easy way to do this...
Should I break down, create a "dummy" Member record with a "1" as the MemberID and use that whenever an Anonymous Visitor needs to be logged?
There must be a better way to go about all of this...
Why can't you use 0 with MEDIUMINT UNSIGNED???
Oh, I see...because you can't have a PRIMARY KEY with value 0 in that case.
I had a similar problem, but my primary key field was signed, not unsigned, so I just used -1 as my "catch all" and that you can do. I don't know why MySQL treats zero as "poison".
Hate to say it, but under the circumstances I'd go with the "1 means not a member" hack.
FWIW I think it's a pretty silly restriction that MySQL imposes. It's truly idiotic that, for the purpose of auto_increment fields (and in some other places) they treat zero and null as being equivalent. I think they must be too used to PHP sloppiness. <grin/>
So I guess that gives me what I want, although I must confess being able to INSERT a NULL and not have a dummy Member record of "0" would be best.
> you *can* run and UPDATE and change the Int AutoIncrement from <whatever> to "0".
A hack, but not a horrible one.
|All times are GMT +1. The time now is 03:25 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.