Jump to content

[SOLVED] Need help If statement


work_it_work

Recommended Posts

i have this code which works perfectly:

 

   <? if ($item_details['category_id'] == '217') { ?>
   <tr class="c1">
      <td width="150" align="right"><?=MSG_ITEM_SUBTITLE;?></td>
      <td><input name="subname" type="text" id="subname" value="<?=$item_details['subname'];?>" size="60" maxlength="125" /></td>
   </tr>
   <tr class="reguser">
      <td> </td>
      <td><?=MSG_ITEM_SUBTITLE_EXPL;?></td>
   </tr>
   <? } ?>

 

What this code does it output the row if the selected category is "217"

BUT i nee to extend it and don't know how....

What i need is for this IF statement to look in multiple variables not only one like here "217" because i have hundreds of categories... and output the row if the selected category is found, if not, row is not shown.

i need something like this:

<? if ($item_details['category_id'] == '217','218','220','230','240','etc') { ?>
   <tr class="c1">
      <td width="150" align="right"><?=MSG_ITEM_SUBTITLE;?></td>
      <td><input name="subname" type="text" id="subname" value="<?=$item_details['subname'];?>" size="60" maxlength="125" /></td>
   </tr>
   <tr class="reguser">
      <td> </td>
      <td><?=MSG_ITEM_SUBTITLE_EXPL;?></td>
   </tr>
   <? } ?>

I wait for your suggestions...

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/174071-solved-need-help-if-statement/
Share on other sites

the first example it's not suitable for me because i have 5129 categories and it takes a life to do it...

 

i have all the categories numbers saved already like this:

 

'217' , '218' , '219' , '220' , '221' , '222' , '224' , '223' ,

'1886' , '1887' , '1888' , '1889' , '1890'

 

so i need to use an array, can you be more explicit with the array you shown? using my category numbers?

Solved!! thanks for your suggestions Garethp!

 

I did something like this:

 

$array = array('217', '218', '219', '220', '221', '222', '224', '223', 
'1886', '1887', '1888', '1889', '1890', '1891', '1892', '1893', '1894', '1898', '1895', '1896', '1885', '1897', '1899',
'216', '225', '226', '1870', '238', '240', '241', '1871', '242', '255', '243', 
'1872', '244', '1873', '1874', '245', '1875', '1876', '1877', '1883', '1878', '1879', 
'1880', '1881', '1882', '256', '262', '1884')
   <? if(in_array($item_details['category_id'], $array)) { ?>
   <tr class="c1">
      <td width="150" align="right"><?=MSG_ITEM_SUBTITLE;?></td>
      <td><input name="subname" type="text" id="subname" value="<?=$item_details['subname'];?>" size="60" maxlength="125" /></td>
   </tr>
   <tr class="reguser">
      <td> </td>
      <td><?=MSG_ITEM_SUBTITLE_EXPL;?></td>
   </tr>
   <? } ?>

 

Works perfectly!

Thanks again!

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.