Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dynamicly include contents within html

Posted on 2006-11-18
3
Medium Priority
?
217 Views
Last Modified: 2013-11-18
I have the following code:

</tr>

<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            require_once('inc/boxing_sub.inc');
      }
      if (strcmp($_POST['category'], "kickboxing") == 0)
      {
            require_once('inc/kickboxing_sub.inc');
      }
      if (strcmp($_POST['category'], martial") == 0)
      {
            require_once('inc/martial_sub.inc');
      }
      if (strcmp($_POST['category'], "special") == 0)
      {
            require_once('inc/special_sub.inc');
      }
?>

<tr>


as you can see it includes a .inc file as required..... at least i thought i could do that, but the result is an empty page..

if i just did
echo "test"; in the place of the require_once, I get the test echoed out where it should be.

what could be the problem?

thanks
0
Comment
Question by:sakuya_su
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 2000 total points
ID: 17971143
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script (from php.net)

it seems to me that you are trying to include different files depending of which if statement is being called.

personnaly on a situation like that i would go with a switch statement.

switch($_POST['category'];)

        {
             case "boxing":

                include ('inc/boxing_sub.inc');

             break;
        }

        {  case "kickboxing":

                 include ('inc/kickboxing.inc');

             break;
         }

etc.

Gamebits
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 17971169
<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            include('inc/boxing_sub.inc');
      }
      if (strcmp($_POST['category'], "kickboxing") == 0)
      {
            include('inc/kickboxing_sub.inc');
      }
      if (strcmp($_POST['category'], martial") == 0)
      {
            include('inc/martial_sub.inc');
      }
      if (strcmp($_POST['category'], "special") == 0)
      {
            include('inc/special_sub.inc');
      }
?>

the above code still generate no contents

but if i did:
<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            echo "why";
        }
?>

if echos why at the correct location..

any ideas?

thanks
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 17971177
hahahaha oh wow that was stupid of me :P

     if (strcmp($_POST['category'], martial") == 0)

missing quote with error report disabled (I just installed a new PHP and the error reporting was on none it seems)

and also $_POST is meant to be $_GET :P

thanks for your help, I will give you the points none the less
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question