Interesting problem

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
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Interesting problem

Post by InnerShadow »

As far as i know, the copy paste function doesn't miss things, however this script that used to work doesn't know, and it does't return any errors, so i know it's not the IF/ELSE statements, it's the mysql update, but im not sure what to change since it isn't giving me any errors.




EDIT: nvm, in looking at my submission, the answer hit me. Sry to waste time.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

I know you already solved your problem, but what was the point of posting this without posting example code or anything that could hint us what your problem is?
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

i did, but it was really long, so i took it out when i solved it
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

here it is if you want it:

Code: Select all

<?php


$LResource = $_POST['LResource'];
if($ID == "United States" or "Great Britain" or "France" or  "Spain"){
	$Check = "yes";
} else if($ID == "Nicaragua"){
	if($LResource == "Timber" or "Fruit" or "Vegetables" or "Sugar" or "Tobacco" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Hawaii"){
	if($LResource == "Timber" or "Fruit" or "Vegetables" or "Sugar"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Panama"){
	if($LResource == "Iron" or "Timber" or "Fruit" or "Vegetables" or "Sugar" or "Tobacco" or "Silver" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Jamaica"){
	if($LResource == "Fruit" or "Vegetables" or "Cotton" or "Sugar" or "Tobacco" or "Silver"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "India"){
	if($LResource == "Coal" or "Iron" or "Timber" or "Vegetables" or "Cotton" or "Silver"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Sudan"){
	if($LResource == "Coal" or "Cotton" or "Sugar" or "Tobacco" or "Silver" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Libya"){
	if($LResource == "Iron" or "Cotton" or "Sugar" or "Tobacco" or "Silver" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Algeria"){
	if($LResource == "Cotton" or "Sugar" or "Tobacco" or "Silver" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Vietnam"){
	if($LResource == "Timber" or "Fruit" or "Cotton" or "Sugar" or "Tobacco"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Costa Rica"){
	if($LResource == "Fruit" or "Vegetables" or "Sugar" or "Tobacco" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Philippines"){
	if($LResource == "Coal" or "Iron" or "Timber" or "Fruit" or "Vegetables" or "Sugar" or "Tobacco" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "China"){
	if($LResource == "Coal" or "Iron" or "Timber" or "Fruit" or "Vegetables" or "Cotton" or "Sugar" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Puerto Rico"){
	if($LResource == "Fruit" or "Vegetables" or "Cotton" or "Sugar" or "Tobacco"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
} else if($ID == "Cuba"){
	if($LResource == "Timber" or "Fruit" or "Vegetables" or "Cotton" or "Sugar" or "Tobacco" or "Gold"){
		$Check = "yes";
	} else {
		$Check = "no";
	}//end if
}//end if






if($Check == "yes"){
	$conn = mysql_connect("localhost", "root", "") or die('Could not connect to the database: '.mysql_error()); 
	mysql_select_db("countries", $conn) or die('Could not select the database: '.mysql_error()); 
	$sql = "update bonuses set LargePlantation = '$LResource' where convert(country using utf8) = '$ID' limit 1"; 
	$res = mysql_query($sql) or die(mysql_error().'<p>SQL:<br />'.$sql.'</p>');

	print "Resource Augmented";
} else {
        print "you can't augment what you don't have";
}//end if
?>
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

look at arrays and the switch statement if you want to make that much prettier :)
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

the problem is it ends up being just about as long as each possibility has different parameters, plus i was more comfortable with IF/ELSE statements when i wrote it, and i haven't gotten around to rewritting it along with the newer scripts.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

InnerShadow wrote:i did, but it was really long, so i took it out when i solved it
Fair enough, :-)
Post Reply