NotSureILikePHP Posted July 15, 2015 Share Posted July 15, 2015 (edited) I am trying to call something simple like Customer->getID() but it causes things on the page to dissappear. When I try to echo out the ID I get nothing. The class is attached in a file. I am trying to call it with the following code: $custs = Cust::getCustomers(); $count = count($custs); <?php if ($count) { //$custs = Cust::getCustomers(); $ids= ($errors && is_array($_POST['ids'])) ? $_POST['ids'] : null; foreach ($custs as $cust) { $id = $cust->id(); $name = $cust['cust_name']; ?> <tr id="<?php echo $id; ?>"> <td width=7px> <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $id; ?>" <?php echo $sel? 'checked="checked"' : ''; ?> <?php echo $default? 'disabled="disabled"' : ''; ?> > </td> <td><?php echo $name; ?></td> </tr> <?php } //end of foreach. } ?> I know the count is 229 because if I add an echo statement after assigning the count I get 229. I have tried getting the properties with ->id() ->getID() and $cust['id'] Edited July 15, 2015 by Maq Quote Link to comment Share on other sites More sharing options...
Maq Posted July 15, 2015 Share Posted July 15, 2015 Please use the code tags in the future, thanks. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 Try putting the start PHP mode tag before the calls instead of after them. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 15, 2015 Share Posted July 15, 2015 I am trying to call something simple like Customer->getID() but it causes things on the page to dissappear. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying the errors it detects? Quote Link to comment Share on other sites More sharing options...
NotSureILikePHP Posted July 15, 2015 Author Share Posted July 15, 2015 That is extremely helpful! And sorry about the tags. I wasn't sure how to tag around html and php at the same time and still make the code readable for people. I figured that might get confusing. Quote Link to comment Share on other sites More sharing options...
NotSureILikePHP Posted July 15, 2015 Author Share Posted July 15, 2015 So there are multiple errors but the first one it give me is undefined index here is line 15: && $sortOptions[strtolower($_REQUEST['sort'])]) ? strtolower($_REQUEST['sort']) : 'name'; ] the array is set before then on line 7 and it's as follows: [ code $sortOptions=array( 'name' => 'cust_name','contact' => 'contact','phone'=> 'phone_number','address'=> 'address'); ] I'm not sure why it's throwing that error. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 15, 2015 Share Posted July 15, 2015 code tags are the word 'code' inside [] to start and [/] to close with your code in between. Quote Link to comment Share on other sites More sharing options...
maxxd Posted July 16, 2015 Share Posted July 16, 2015 It's possible the error is referring to the attempt to read $_REQUEST['sort'] - try print("<pre>".print_r($_REQUEST, true)."</pre>"); before line 15. Also - and this is more a personal preference, so take it with a grain of salt and all, but don't use $_REQUEST. Variables in the $_REQUEST superglobal can come from $_GET, $_POST, $_SESSION, or $_COOKIE. Know what data you're looking for and where to find it. If you submit your form using post, check $_POST; if you submit using get, check $_GET. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 16, 2015 Share Posted July 16, 2015 So there are multiple errors but the first one it give me is undefined index Which index is it referring to? The one for $_REQUEST...or the one for $sortOptions? To avoid this type of error, you could use isset(): $sort = (isset($_REQUEST['sort']) && isset($sortOptions[strtolower($_REQUEST['sort'])])) ? strtolower($_REQUEST['sort']) : 'name'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.