Jump to content

include into function


grucker

Recommended Posts

Thank you both. So now face.php has

 

<?= render_products('face');?>

 

The templates.php  page has

 

$funcname = 'get_xml_'.$area;

foreach($funcname() as $product)

 

{

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  '

 

   

  <td valign="top">

      <b class="b1h"></b><b class="b2h"></b><b class="b3h"></b><b class="b4h"></b>

                <div id="' . $product->id . '" class="product">

                  <div class="productdescription_face">

                <h3>' . $product->title . '</h3>

             

                    <br/>

                      <p style="text-align:center;"> <img src="' . $product->img . '"  alt="'.$product->alt.'"  /></p>

                          <p>' . $product->description . '</p>

                           

              </div>

                 

              <div style="margin-bottom:15px">

                              <p><b>' . $product->info . ' </b></p>

              </div>

             

                    <div class="price">

             

              <p><b>' . $product->size . '        

                      £' . $product->price .'</b></p>

                                       

                    </div>

             

              <div class="addToCart">

                           

                        <form action="../addToCart.php" method="post">

                        <p>

                        <input type="hidden" name="id" value="'.$product->id.'" />

                        <input class="red" type="submit" value="Add To Shopping Basket" />

                      </p>

                        </form>

                  </div>

           

             

                </div>

                    <b class="b4bh"></b><b class="b3bh"></b><b class="b2bh"></b><b class="b1h"></b>

 

          </td>

        ';

   

        if ($i >= 2){

            // start new row

            $output .= "</tr><tr>";

            // reset loop

            $i = 0;

        }

 

        else

            $i++;

    }

 

      if ($i == 1)

        $output .= '<td></td><td></td>';

    else if ($i == 2)

        $output .= '<td></td>';

 

    $output .= '</tr></table>';

     

    return $output;

?>

 

 

but unfortunately the following is showing

 

Notice: Undefined variable: area in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 2

 

Fatal error: Call to undefined function get_xml_() in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 3

 

so in templates i put

function render_products($area)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  ' and the rest.

and got loads of errors.

 

so then i did

function render_products($area)

{$funcname = 'get_xml_'.$area;

foreach($funcname() as $product)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  ' and the rest

and got

Notice: Undefined variable: i in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 61

 

Notice: Undefined variable: i in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 63

 

Notice: Undefined variable: output in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 66

 

 

I really appreciate the help you are both giving me but some is going over my head. Fortunately if It wont work It doesnt alter the site. Just got a bee in my bonnet and thought it should be possible.

Thanks again.

Regards

David

 

   

 

Do you really think so?

The attached files are the original  working files Then in face.php I put

 

<?= render_products('face');?>

 

and in templates.php removed all the face body bath etc and just put the one function in starting

function render_products($area)

{$funcname = 'get_xml_'.$area;

foreach($funcname() as $product)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  '

Do you really think it will work?

Regards

David

 

[attachment deleted by admin]

Do you really think so?

The attached files are the original  working files Then in face.php I put

 

<?= render_products('face');?>

 

and in templates.php removed all the face body bath etc and just put the one function in starting

function render_products($area)

{$funcname = 'get_xml_'.$area;

foreach($funcname() as $product)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  '

Do you really think it will work?

Regards

David

 

so did this work?

No unfortunately it did not work. Kept finding fault with lines 60ish in the template file.

 

Here are the deyails from a previous poosting.

 

so in templates i put

function render_products($area)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  ' and the rest.

and got loads of errors.

 

so then i did

function render_products($area)

{$funcname = 'get_xml_'.$area;

foreach($funcname() as $product)

    $output = "<table class='products'><tr>";

    $i = 0;

    $output .=  ' and the rest

and got

Notice: Undefined variable: i in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 61

 

Notice: Undefined variable: i in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 63

 

Notice: Undefined variable: output in E:\domains\s\sites4eyes.co.uk\user\htdocs\Paypalwebstore\htdocs\mulberry\functions\templates.php on line 66

 

 

Well done old chap. Works, just tried it on some of the others to make sure. Would it be possible to let me know why it works and is the function file still needed? Still dont understand $area as I cannot see a definition. Ah well thanks again. I will post as solved tomorrow.

Regards

David

the function.php file is needed as that is where you define your get_xml_ functions as well as include the template.php file.

 

basically you are now passing in the variable you need to call the specific get_xml_ function.

 

so face.php passes "face" into the function. "face" which is now defined as $area in the function gets concatenated to get_xml_$area = get_xml_face and therefore calls the appropriate function defined in the function.php file.

 

hope that makes sense. i'm not the best at explaining.

Archived

This topic is now archived and is closed to further replies.

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