farkewie Posted April 16, 2008 Share Posted April 16, 2008 HI, I am trying to error check values of an array, i want to make sure they have a correct value to build a table but its not setting the array value to correct number. <?php // fetch config import('classes.modul.ModulService'); import('classes.modul.Modul'); import('classes.menu.MenuService'); import('classes.util.LinkHelper'); // fetch config $config = array( 'show_hidden', 'content_top', 'content_bottom', 'show_description', 'column_width', 'table_columns', 'table_border', ); //Check the config for incorrect values!! if ($config['table_columns'] == "O"){ $config['table_columns'] = "2"; } if (! is_numeric($config['table_columns'])) { $config['table_columns'] = "2"; } //Finished Error Checkng ?> So basicly i want to make sure there is a valid value entered in to table_columns to make sure it builds a proper table. but when i set table_columns to 0 it doesnt reset it to 2. Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/ Share on other sites More sharing options...
Cep Posted April 16, 2008 Share Posted April 16, 2008 Your referencing an index doing this, $config['table_columns'] but you actually have a numeric array so for the value table_columns you would reference it like $config[5], do you follow me? Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/#findComment-518321 Share on other sites More sharing options...
Cep Posted April 16, 2008 Share Posted April 16, 2008 To provide a further example of what I mean, <?php // Numeric array with numbered indexes and string values // fetch config $config = array( 'show_hidden', 'content_top', 'content_bottom', 'show_description', 'column_width', 'table_columns', 'table_border', ); // Associative array with string indexes and string values // fetch config $config = array( 'show_hidden' => "a value", 'content_top' => "a value", 'content_bottom' => "a value", 'show_description' => "a value", 'column_width' => "a value", 'table_columns' => "a value", 'table_border' => "a value", ); ?> Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/#findComment-518326 Share on other sites More sharing options...
farkewie Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks for the reply, This is what the origional code looked liek and the error cecking is just what i have added to is. <?php import('classes.modul.ModulService'); import('classes.modul.Modul'); import('classes.menu.MenuService'); import('classes.util.LinkHelper'); // fetch config $config = array( 'show_hidden' => true, 'content_top' => false, 'content_bottom' => true, 'show_description' => true, 'column_width' => "225", 'table_columns' => "2", 'table_border' => "0", ); //Check the config for incorrect values!! if ($config['table_columns'] == "O"){ $config['table_columns'] = "2"; } if (! is_numeric($config['table_columns'])) { $config['table_columns'] = "2"; } //Finished Error Checkng ?> and this is the whole script. the only this that im adding to it is the table so it used to just be divtage but i wanted to use tables. <?php /* * File: modul.php * Version: 1.0 * * Copyright 2008 Tyron Gower <[email protected]> * */ ?> <?php import('classes.modul.ModulService'); import('classes.modul.Modul'); import('classes.menu.MenuService'); import('classes.util.LinkHelper'); // fetch config $config = array( 'show_hidden' => true, 'content_top' => false, 'content_bottom' => true, 'show_description' => true, 'column_width' => "225", 'table_columns' => "2", 'table_border' => "0", ); //Check the config for incorrect values!! if ($config['table_columns'] == "O"){ $config['table_columns'] = "2"; } if (! is_numeric($config['table_columns'])) { $config['table_columns'] = "2"; } //Finished Error Checkng $modulService = new ModulService(); $modul = new Modul($GLOBALS['MENU']->getModulID()); $config = $modulService->getModulProperties($MENU, $modul, $config); /* ######################################################################### * ############################ Show Admin Link ########################## * ######################################################################### */ if ($modul->isModulAdmin()) { import('classes.util.links.ModulAdminLink'); $mdl = new ModulAdminLink(); $mdl->setItemID($MENU->getID()); $mdl->setLanguageID($MENU->getLanguageID()); ?> <script type="text/javascript"> <!-- function openAdmin() { fenster = open("<?php echo LinkHelper::getUrlFromCMSLink($mdl); ?>","ModulAdmin","menubar=no,toolbar=no,statusbar=no,directories=no,location=no,scrollbars=yes,resizable=no,height=350,width=400,screenX=0,screenY=0"); bBreite=screen.width; bHoehe=screen.height; fenster.moveTo((bBreite-400)/2,(bHoehe-350)/2); } // --> </script> <?php echo '<div class="modulAdminLink" align="left"><a onClick="openAdmin(); return false;" href="'.LinkHelper::getUrlFromCMSLink($mdl).'"><img src="'.$GLOBALS['_BIGACE']['DIR']['public'].'system/images/preferences.gif" border="0" align="top"> '.getTranslation('modul_admin_link').'</a></div>'; } // display content below submenus?!? if($config['content_top']) { $mService = new MenuService(); echo $GLOBALS['MENU']->getContent(); unset($meService); } echo '<div id="preview">'; $ir = new ItemRequest($itemtype); $ir->setID($GLOBALS['MENU']->getID()); $ir->setLanguageID($GLOBALS['MENU']->getLanguageID()); $ir->setItemType(_BIGACE_ITEM_MENU); if($config['show_hidden']) { $ir->setFlagToExclude($ir->FLAG_ALL_EXCEPT_TRASH); } $ir->setOrderBy($params['orderby']); $ir->setOrder($params['order']); $menus = new SimpleItemTreeWalker($ir); $in = 0; $cols = $config['table_columns']; print "<table border=\"".$config['table_border']."\" ><tr>"; for ($i=0; $i < $menus->count(); $i++) { print "<td width=\"".$config['column_width']."\" valign=\"top\"><div class=\"nextLevelPreview\">"; $temp_menu = $menus->next(); $url = LinkHelper::getUrlFromCMSLink( LinkHelper::getCMSLinkFromItem($temp_menu) ); // echo '<div class="nextLevelPreview">'; echo '<h3><a href="'.$url.'" title="'.$temp_menu->getName().'">'; echo $temp_menu->getName(); echo '</a></h3><p>'; if (($config['show_description']) == true) { if( strlen(trim($temp_menu->getDescription())) > 0 ) echo $temp_menu->getDescription(); else echo getTranslation('empty_description'); echo ' <a href="'.$url.'" title="'.getTranslation('list_link_title').$temp_menu->getName().'"><img border="0" src="'.$GLOBALS['_BIGACE']['DIR']['public'].'modul/images/3arrows.gif" alt="'.getTranslation('list_img_alt').'"></a>'; '</p></div>'; } print "</div></td>"; $in++; if ($in == $cols) { print"</tr><tr>"; unset($in); } } print "</tr></table>"; echo '</div>'; // display content below submenus?!? if($config['content_bottom']) { $mService = new MenuService(); echo $GLOBALS['MENU']->getContent(); unset($meService); } ?> Any help would be great Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/#findComment-518329 Share on other sites More sharing options...
Cep Posted April 16, 2008 Share Posted April 16, 2008 Ok, I have two questions. 1. Is table_columns always going to be 2? If so don't use a variable use a constant. 2. What are you trying to accomplish with your error checks, they don't really appear to do much. Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/#findComment-518334 Share on other sites More sharing options...
farkewie Posted April 16, 2008 Author Share Posted April 16, 2008 You are right, i had a think about what i was doing and there really was no point.. lol i think after getting error checking drummed in to me now i try and take it to far sometime. Thanks for your replys Link to comment https://forums.phpfreaks.com/topic/101336-trying-to-do-error-checking-on-array-values/#findComment-518373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.