1

In the system.log I have thousands of entries saying: ERR (3): Notice: Undefined offset: 0 in /home//public_html/app/design/frontend/base/default/template/uploadpdf/uploadpdf.phtml on line 10

So the code is:

<?php
$current_product = Mage::registry('current_product');
$productid = $current_product->getEntityId();

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
            //echo "SELECT * from ifuturz_uploadpdf WHERE product_id='$pid'     ";
            $readresult=$write->query("SELECT * from ifuturz_uploadpdf WHERE product_id='$productid' ");
            $entityid = $readresult->fetchAll();
            //echo "<pre>";print_r($entityid);
            $eid =  $entityid[0]['pdf_file'];   <======= LINE:10
            if($eid!='')
            {
            ?>
                <div class="collateral-box">
                    <div class="head">
                            <h4><?php echo $this->__('PDF Downloads') ?>    </h4>
                    </div>
                </div>
                <?php

                for($i=0; $i<count($entityid) ;$i++)
                {
                    //echo     Mage::getBaseUrl('media')."pdffiles/uploadedfiles/".$entityid[$i]['pdf_path'];
                    $front = $entityid[$i]['pdf_file'];
                $pdfnm = $entityid[$i]['pdfname'];
                //$pdfnew = explode('/',$pdf);
                //$pdfexp = $pdfnew[8];
                //$pdffinal = str_replace('.pdf','',$pdfexp);

                if($pdfnm == "")
                {
                    $ext = explode(".", $front);
                    echo '<li style="font-family: verdana;margin-bottom: 15px;margin-left: 10px;"><a target="_blank" href="'.$entityid[$i]['pdf_path'].'">'.$ext[0].'</a><br /></li>';
                }
                else
                {
                    echo '<li style="font-family: verdana;margin-bottom: 15px;margin-left: 10px;"><a target="_blank" href="'.$entityid[$i]['pdf_path'].'">'.$pdfnm.'</a><br /></li>';
                }
            }
        }
        //echo "<pre>"; print_r($entityid);
        ?>

I guess there should be an extra if statement that catches the 0 exception right ? But how to do this properly in php ?

closed as off-topic by Murtuza Zabuawala, Rakesh Jesadiya, Qaisar Satti, 7ochem, Amit Bera Feb 8 '17 at 12:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Murtuza Zabuawala, Rakesh Jesadiya, Qaisar Satti, 7ochem, Amit Bera
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Never use Ifuturz's extension(very poor quality work they do) – Vaibhav Ahalpara Feb 8 '17 at 8:21
1

Make this line

$eid =  $entityid[0]['pdf_file'];

look like this

$eid =  isset($entityid[0]['pdf_file']) ? $entityid[0]['pdf_file'] : '';
  • This indeed did the trick ... many thanks for saving my MegaBytes ! – van den HeuvelConcepts Feb 9 '17 at 9:56
0

First, make sure that you copy app/design/frontend/base/default/template/uploadpdf/uploadpdf.phtml to your theme folder in order to over-ride it.

Then, you need to take a look at what $entityid actually returns. var_dump the variable within the template.

Looking at how it's being called, it should return an array, where each entry has a ['pdf_file'] key to another array.

To check for this in PHP I'd probably look at two commands.

Firstly, is this an array? is_array - I would assume it is, as you're getting undefined offset, and not a message about manipulating something other than an array.

Secondly, does the offset exist? array_key_exists, something like:

if (array_key_exists('0', $entityid)) {
0

You need to check the response of this code :

$readresult = $write->query("SELECT * from ifuturz_uploadpdf WHERE 'product_id='$productid' ");
 $entityid = $readresult->fetchAll();

            echo "<pre>";
print_r($entityid);

            $eid =  $entityid[0]['pdf_file'];

Check the response if the return array have a value at its "0" index or not.

For check this condition you can use this code :

array_key_exists('0', $entityid)

Not the answer you're looking for? Browse other questions tagged or ask your own question.