Jump to content

Archived

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

Tjk

Function using preg_match and stristr problem

Recommended Posts

The first part of the script is the opening to the function called itemslot. It instructs that if it matches the word reach or bow within the string $itemslot then it will run a query to get the value of waref from a table and store it in the var $iwe, I combine $et and $refslot values (for use with different refslot values) to create the string for the var $intxt which runs the mysql query to find out if the item has a name and if so stores it in the $ietxt. However it doesn't seem to work and I don't know why.

In the table item1name has the value 'aaa' and item2name has the value 'bbb'.

[code]
<?
$armcheck= "0";

function itemslot($itemslot){
  
    global $refslot;
    global $dis;
    global $itxt;
    global $armcheck;
  
    if(preg_match("/reach/i", $itemslot) || preg_match("/bow/i", $itemslot)){      
        $wquery= mysql_query("SELECT waref FROM Items WHERE name='$itemslot'")or die(mysql_error());        
        while($wrow= mysql_fetch_array($wquery)){
        $iwe= $wrow['waref'];
        }
        $et= "name";
        $intxt= $refslot.$et;        
        $inquery= mysql_query("SELECT $intxt FROM pcitems WHERE userid='$userid'")or die(mysql_error());
        while($inrow= mysql_fetch_array($inquery)){
        $iname= $inrow[$intxt];
        }
        if($iname != ""){
        $ietxt= "<i>Called: ". ucwords(strtolower($iname)). "</i>";
        }
        else{
        $ietxt= "";
        }
[/code]

The second part of my script compares the value of $itemslot and it will then create option values stored in the variable $itxt to be echoed in <SELECT> box in the HTML. I use $armcheck so that if $itxt already contains some text it will simply add it onto the end. But for some reason this entire function (script above and below parts) doesn't want to work.

The value for $item1slot is 'med reach +1 war' and $item2slot is 'short bow +3 war'.

[code]
      if(stristr($itemslot, 'bow') === FALSE){
        if(stristr($itemslot, 'long') === FALSE){
            if(preg_match("/short/i", $itemslot)){
              if($armcheck == "1"){
              $itxt= $itxt. "<option value='$refslot'>Short Reach Weapon (+$iwe war) $ietxt ($dis) </option>";
            }
            else{
              $itxt= "<option value='$refslot'>Short Reach Weapon (+$iwe war) $ietxt ($dis) </option>";
              $armcheck= "1";
            }
            }
            else if(preg_match("/medium/i", $itemslot)){
              if($armcheck == "1"){
              $itxt= $itxt. "<option value='$refslot'>Medium Reach Weapon (+$iwe war) $ietxt (". $dis. ")</option>";
            }
            else{
              $itxt= "<option value='$refslot'>Medium Reach Weapon (+$iwe war) $ietxt (". $dis. ")</option>";
              $armcheck= "1";
            }
            }
            else if(preg_match("/shield/i", $itemslot)){
            if(preg_match("/large/i", $itemslot)){
              if($armcheck == "1"){
                $itxt= $itxt. "<option value='$refslot'>Large Shield (+$iwe war) $ietxt (". $dis. ")</option>";
              }
              else{
                $itxt= "<option value='$refslot'>Large Shield (+$iwe war) $ietxt (". $dis. ")</option>";
                $armcheck= "1";
              }              
            }
            else if(preg_match("/medium/i", $itemslot)){
              if($armcheck == "1"){
                $itxt= $itxt. "<option value='$refslot'>Medium Shield (+$iwe war) $ietxt (". $dis. ")</option>";
              }
              else{
                $itxt= "<option value='$refslot'>Medium Shield (+$iwe war) $ietxt (". $dis. ")</option>";
                $armcheck= "1";
              }              
            }
            else if(preg_match("/small/i", $itemslot)){
              if($armcheck == "1"){
                $itxt= $itxt. "<option value='$refslot'>Small Shield (+$iwe war) $ietxt (". $dis. ")</option>";                
              }
              else{
                $itxt= "<option value='$refslot'>Small Shield (+$iwe war) $ietxt (". $dis. ")</option>";
                $armcheck= "1";
              }                
            }        
            }
        }
        else{
          if($armcheck == "1"){
            $itxt= $itxt. "<option value='$refslot'>Long Reach Weapon (+$iwe war) $ietxt (Dual Wielded) (". $dis .")</option>";
          }
          else{
            $itxt= "<option value='$refslot'>Long Reach Weapon (+$iwe war) $ietxt (Dual Wielded) (". $dis .")</option>";
            $armcheck= "1";
          }
        }
      }
      else{
        if(preg_match("/short/i", $itemslot)){
          if($armcheck == "1"){
            $itxt= $itxt. "<option value='$refslot'>Short Bow (+$iwe war) (Dual Wielded) $ietxt (". $dis. ")</option>";            
          }
          else{
            $itxt= "<option value='$refslot'>Short Bow (+$iwe war) (Dual Wielded) $ietxt (". $dis. ")</option>";
            $armcheck= "1";
          }
            
        }
        else{
          if($armcheck == "1"){
            $itxt= $itxt. "<option value='$refslot'>Long Bow (+$iwe war) (Dual Wielded) $ietxt (". $dis. ")</option>";  
            }
            else{
            $itxt= "<option value='$refslot'>Long Bow (+$iwe war) (Dual Wielded) $ietxt (". $dis. ")</option>";  
            $armcheck= "1";
          }          
        }    
      }      
    }
}
//end of function

if($item1slot != ""){
  $dis= "Item Slot 1";
  $itemslot= $item1slot;
  $refslot= "item1";
  item($itemslot);
}
if($item2slot != ""){
  $dis= "Item Slot 2";
  $itemslot= $item2slot;
  $refslot= "item2";
  item($itemslot);
}
?>

<select name='items'>
<?
echo $itxt;
?>
</select>
[/code]

Could help me out with this. Thanks in advance.

Regards.

Share this post


Link to post
Share on other sites

×

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.