Solved

dynamicly include contents within html

Posted on 2006-11-18
3
176 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
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 500 total points
Comment Utility
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
Comment Utility
<?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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now