grucker Posted March 1, 2010 Author Share Posted March 1, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020036 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 Ok this shows us that the problem all along. was that the variable $area has no value. So we need to make sure it does have a value. Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020074 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 So, to get this to work, the function definition needs to be function render_products($area) { ..... } to fit in with the other changes you have made Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020080 Share on other sites More sharing options...
grucker Posted March 1, 2010 Author Share Posted March 1, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020097 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020103 Share on other sites More sharing options...
grucker Posted March 1, 2010 Author Share Posted March 1, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020118 Share on other sites More sharing options...
schilly Posted March 1, 2010 Share Posted March 1, 2010 it should. where are you including templates.php in face.php? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020137 Share on other sites More sharing options...
grucker Posted March 1, 2010 Author Share Posted March 1, 2010 Head of the page it says require_once '../../functions/functions.php'; and in the functions file are all the links for the templates. I thought maybe the function file was involved. Regards Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020143 Share on other sites More sharing options...
schilly Posted March 1, 2010 Share Posted March 1, 2010 ah k i see it now in functions.php. looks good. Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020145 Share on other sites More sharing options...
schilly Posted March 2, 2010 Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020629 Share on other sites More sharing options...
grucker Posted March 2, 2010 Author Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020635 Share on other sites More sharing options...
schilly Posted March 2, 2010 Share Posted March 2, 2010 see my file. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020644 Share on other sites More sharing options...
grucker Posted March 2, 2010 Author Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020657 Share on other sites More sharing options...
schilly Posted March 2, 2010 Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020666 Share on other sites More sharing options...
grucker Posted March 2, 2010 Author Share Posted March 2, 2010 Yes I understood that part just not sure about the area word. Would it still work with another name? Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020669 Share on other sites More sharing options...
schilly Posted March 2, 2010 Share Posted March 2, 2010 yea could change that to whatever you want. Link to comment https://forums.phpfreaks.com/topic/193231-include-into-function/page/2/#findComment-1020684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.