Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('dbcon.php');
- $getions = mysql_query("SELECT * FROM ions");
- $elements = array();
- $charges = array();
- $ides = array("oxygen" => "oxide", "nitrogen" => "nitride", "flourine" => "flouride", "phosphorus" => "phosphide", "sulfur" => "sulfide", "chlorine" => "chloride", "arsenic" => "arsenide", "bromine" => "bromide", "iodine" => "iodide");
- function toIde($element) {
- global $ides;
- $out = $ides[$element];
- return $out;
- }
- while($result = mysql_fetch_array($getions)) {
- array_push($elements,$result['name']);
- array_push($charges, $result['charges']);
- }
- function getElementCharge($element) {
- global $elements, $charges;
- $key = array_search($element, $elements);
- $charge = $charges[$key];
- return $charge;
- }
- function nameCompound($element1, $element2) {
- global $elements, $charges;
- $arr = array($element1, $element2);
- $name1 ="";
- $name2="";
- foreach($arr as $i) {
- $charge = getElementCharge($i);
- if($charge > 0) {
- $name1 = $i;
- }
- else if($charge < 0) {
- $name2 = $i;
- }
- }
- return $name1 . toIde($name2);
- }
- print nameCompound("oxygen","lithium");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement