work_it_work Posted September 13, 2009 Share Posted September 13, 2009 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 More sharing options...
Garethp Posted September 13, 2009 Share Posted September 13, 2009 if($item_details['category_id'] == '217' || $item_details['category_id'] == '218' || $item_details['category_id'] == '220') Or put what you want in an array, then if(in_array($item_details['category_id'], $Array)) Link to comment https://forums.phpfreaks.com/topic/174071-solved-need-help-if-statement/#findComment-917589 Share on other sites More sharing options...
work_it_work Posted September 13, 2009 Author Share Posted September 13, 2009 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? Link to comment https://forums.phpfreaks.com/topic/174071-solved-need-help-if-statement/#findComment-917592 Share on other sites More sharing options...
Garethp Posted September 13, 2009 Share Posted September 13, 2009 $Array = array(); $Array[] = '217'; $Array[] = '218'; $Array[] = '219'; if(in_array($item_details['category_id'], $Array)) Link to comment https://forums.phpfreaks.com/topic/174071-solved-need-help-if-statement/#findComment-917594 Share on other sites More sharing options...
work_it_work Posted September 13, 2009 Author Share Posted September 13, 2009 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! Link to comment https://forums.phpfreaks.com/topic/174071-solved-need-help-if-statement/#findComment-917604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.