Jump to content

$name = IFSTRING


Monk3h

Recommended Posts

Im trying to put an if string inside a variable define string.

 

Any ideas on the syntax?

 

Example:

$key = "Empty";

$keycheck = if ($key == 'Empty'){                             // Line 7
Print "<img src=images/keyneautural.php>";

};

 

Error:

Parse error: syntax error, unexpected T_IF in /home/monk3h/public_html/projectalpha/alphaground.php on line 7

Link to comment
https://forums.phpfreaks.com/topic/111655-name-ifstring/
Share on other sites

How do you do that? :S

 

<?php
   function keyCheck($key)
   {
      if($key == "empty")
      {
         $string = "<img src='images/keyneautural.php'>"; //are you sure you're not trying to spell 'neutral'?
      }
      else
      {
         $string = "";
      }

      return $string;
   }

   $myImg = keyCheck("empty");
?>

Link to comment
https://forums.phpfreaks.com/topic/111655-name-ifstring/#findComment-573490
Share on other sites

Okay, im very Confused.

 

What i'm trying to do is make a map.

 

I have an 11X11 Table and in each of the 121 <td>s i have Redefined what $id is.

 

Then after i Print the $keycheck. which should pick up on what the new ID is and then Print the image that is alocated to that id.

 

Here is an example.

 

 

$keycheck example:

 

$check = mysql_fetch_array(mysql_query("SELECT * FROM `alphaground` WHERE `id` = '$id'"));

if ($check[owner] == 0){

$keycheck = "<img src= images/keyneautural.png>";

}else{

$keycheck = "<img src= images/keyalliance.png>";

}

 

 

 

Table Example:

 

<td width='290' height='290' bgcolor='#66CCFF'><table width='210' border='0' align='center' cellpadding='0' cellspacing='0'>
            <tr>
              <td>"; $id = 1; Print "$keycheck </td>
              <td>"; $id = 2; Print "$keycheck </td>
              <td>"; $id = 3; Print "$keycheck </td>
              <td>"; $id = 4; Print "$keycheck </td>
              <td>"; $id = 5; Print "$keycheck </td>
              <td>"; $id = 6; Print "$keycheck </td>
              <td>"; $id = 7; Print "$keycheck </td>
              <td>"; $id = 8; Print "$keycheck </td>
              <td>"; $id = 9; Print "$keycheck </td>
              <td>"; $id = 10; Print "$keycheck </td>
              <td>"; $id = 11; Print "$keycheck </td>
            </tr>
            <tr>
              <td>"; $id = 12; Print "$keycheck </td>
              <td>"; $id = 13; Print "$keycheck </td>
              <td>"; $id = 14; Print "$keycheck </td>
              <td>"; $id = 15; Print "$keycheck </td>
              <td>"; $id = 16; Print "$keycheck </td>
              <td>"; $id = 17; Print "$keycheck </td>
              <td>"; $id = 18; Print "$keycheck </td>
              <td>"; $id = 19; Print "$keycheck </td>
              <td>"; $id = 20; Print "$keycheck </td>
              <td>"; $id = 21; Print "$keycheck </td>
              <td>"; $id = 22; Print "$keycheck </td>
            </tr>

Link to comment
https://forums.phpfreaks.com/topic/111655-name-ifstring/#findComment-573513
Share on other sites

Sounds like you need to employ a while loop:

<?php
   $query = "SELECT * FROM alphaground WHERE id = '$id'";
   $result = mysql_query($query);

   $count = 1;
   $id = 1;

   echo "<table width='210' border='0' align='center' cellpadding='0' cellspacing='0'>";

   while($check = mysql_fetch_assoc($result))
   {
      if($check['owner'] == 0)
      {
         $keycheck = "<img src='images/keyneautural.png'>";
      }
      else
      {
         $keycheck = "<img src='images/keyalliance.png'>";
      }

      if($count > 11) //for every 12 items, create a new row
      {
         echo "</tr><tr><td>$id $keycheck</td>";
         $count = 1;
      }
      else
      {
         echo "<td>$id $keycheck</td>";
      }

      $count++;
      $id++;
   }
?>

 

This code isn't tested by any means, but it should put you on the right track.

Link to comment
https://forums.phpfreaks.com/topic/111655-name-ifstring/#findComment-573617
Share on other sites

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.