Jump to content

Recommended Posts

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 by Maq
Link to comment
https://forums.phpfreaks.com/topic/297314-class-properties-dont-work/
Share on other sites

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?

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.
 

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.

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';
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.