php - Unable to read GET variable when used in $page_content -


i have file called productfocus.php use variable id: $id = $_get["id"]; page used in product.php file in following manner:

product.php

<?php     $page_content = 'productfocus.php'; // $id = $_get["id"];     include('master.php'); ?> 

productfocus.php

<?php     include "db/db.php";     $id = $_get["id"];     $product = get_product_by_id($id); ?>  <div class="product-focus">     <h3><?php echo $product->name ?></h3>     <img src="/images/products/<?php echo $product->image ?>">     <div id="description">         <h4>productinformatie</h4>         <p><?php echo $product->description ?></p>         <h4>partners</h4>         <table>             <?php                 foreach($product->partners_obj $partner) {             ?>             <tr>                 <td>                     <a href=<?php echo $partner->$product_url ?> target="_blank">                         <img id="partner" src="/images/partners/<?php echo $partner->image ?>">                     </a>                 </td>                 <td>                     <a href=<?php echo $partner->$product_url ?> target="_blank"><?php $partner->$product_price ?></a>                 </td>             </tr>             <?php                 }             ?>         </table>     </div> </div> 

master.php

//html code ...  <?php include($page_content);?> ... //html code 

when browse productfocus.php?id=324324 can read variable, when browse product.php?id=324324 not have access variable id.

is there elegant way solve issue?

you need check variable before call product details in prodcts.php file before regular page load.

<?php  if (isset($_get['id'])) {      // product data  }else{      // load products page  }  ?> 

as getting product details, suggest writing separate call database, if need load page content, not calling properly:

$id = $_get['id'];     $fileurl = 'products.php?id='.$id; $pagecontent = file_get_contents('$fileurl'); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -