max_power Posted April 20, 2010 Share Posted April 20, 2010 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 Link to comment https://forums.phpfreaks.com/topic/199118-limiting-the-amount-of-same-variables-that-can-exist-in-mysql-db/ Share on other sites More sharing options...
max_power Posted April 20, 2010 Author Share Posted April 20, 2010 Anyone? Link to comment https://forums.phpfreaks.com/topic/199118-limiting-the-amount-of-same-variables-that-can-exist-in-mysql-db/#findComment-1045095 Share on other sites More sharing options...
SaMike Posted April 20, 2010 Share Posted April 20, 2010 Well in your code you check if two core sponsors exist and if they do, you execute error message. So when you're editing either of those two sponsors, two already exists, thats why it gives out that error? Link to comment https://forums.phpfreaks.com/topic/199118-limiting-the-amount-of-same-variables-that-can-exist-in-mysql-db/#findComment-1045191 Share on other sites More sharing options...
MatthewJ Posted April 20, 2010 Share Posted April 20, 2010 Sounds like a good time to rethink the logic involved Link to comment https://forums.phpfreaks.com/topic/199118-limiting-the-amount-of-same-variables-that-can-exist-in-mysql-db/#findComment-1045195 Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 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. Link to comment https://forums.phpfreaks.com/topic/199118-limiting-the-amount-of-same-variables-that-can-exist-in-mysql-db/#findComment-1045218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.