Jump to content

Limiting the amount of same variables that can exist in mysql db..


max_power

Recommended Posts

Hi all,

 

Basically I have created a sponsor database and I am trying to add a rule that only two Core Sponsor relationship types can exist at any one time. So this rule is for adding and editing. During the adding stage, I have no problem but during the editing phase I have one problem. Now the existing non-Core Sponsor I can edit without any problem and the rule is enforced with no problem as well but if I want to edit an existing Core Sponsor, even if I don't edit the relationship type, it will show me an error saying that 2 core sponsor already exist. It applies to both existing core sponsors. Not sure why this is doing that since both of them are the EXISTING core sponsors and no more core sponsors are being added!

 

Here is the edit part of my code concerning this rule:

 

                 if ($relation == "Core Sponsor")
	{
				$query1 = "SELECT relationship FROM tbl_sponsor where relationship = '$relation'";	 
				$result2 = mysql_query($query1);
				$rows = mysql_num_rows($result2);					
				if($rows == 2)
				{
					echo "Two core sponsors already exist";
				}
				else
				{
					//update query.							
				}
	}

 

The 'if($rows == 2)' is probably causing this but is there any other way to carry out this rule during the editing stage for the two existing Core Sponsors and the rest of the non-Core Sponsors? It seems it is one or the other for me.

 

Thanks,

Max Power

Well, if you're editing a core sponsor, before the UPDATE query, there will of course, be two core sponsors. I don't know what you want to do beyond that point so I can't advice, but if there must be 2 core sponsors at all times, then it's impossible to change a core sponsor to a non-core sponsor. If there must be at most 2, then check if there is 1 other core sponsor in the DB.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.