Solved

dynamicly include contents within html

Posted on 2006-11-18
3
180 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

25 Experts available now in Live!

Get 1:1 Help Now