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

 

Link to comment
Share on other sites

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

 

   

 

Link to comment
Share on other sites

We are making progress here, but your code directly onto the post is difficult to read. Can you post the code of both files, using the php tags provided, and then it will be clearer to read and we can iron out these remaining issues.

 

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.