I'm toying around with taking variables that are passed from a form, into a new page, but only showing specific portions of the site if the variables come out to having a value.

right now im using

if ($seasons=='true')
{
include('includes/seasons.php');  /* seasons show */
} else {
include('includes/products.php');  /* products */
} 
   ?>

Recommended Answers

All 6 Replies

Was there a question or were you just showing us the code?

Well, one would assume yes, a question would be implied in just the posting.

but to spell it out further (understandably) is that the correct syntax for testing the variable if its true showing the first, else it would then show the second portion?

Well that depends on what you want to test. If you want to test for boolean true you'd say

if ($somevariable)

If you wanted to test if the variable was equal to the string "true" then you'd use your way.

I did actually try a variation on the code, as I realized I was checking the wrong variable it should be checking the radio group, so I altered the code slightly

if ($radio='seasons')
{
include('includes/seasons.php');  /* seasons show */
}

if ($radio='products')
{
include('includes/products.php');
}
   ?>

of course its actually showing BOTH currently, mostly likely because i should be using double equals im guessing

I did actually try a variation on the code, as I realized I was checking the wrong variable it should be checking the radio group, so I altered the code slightly

if ($radio='seasons')
{
include('includes/seasons.php');  /* seasons show */
}

if ($radio='products')
{
include('includes/products.php');
}
   ?>

of course its actually showing BOTH currently, mostly likely because i should be using double equals im guessing

Yes, == is a test, = is an assignment. $var = "string" in a condition will always be true.

thanks, was pretty sure that was the case, and I know of course that since I was testing the wrong variable in the first example, it would show the incorrect thing.

gotta learn it step by step.. hah.

at any rate, this SEEMS to work now, now I just have to take into account some other code, might be back to this topic, just kind of depends.

this portion of the code is actually part of another post I put up, but I decided to use a new thread, since this code actually has almost nothing to do with the original thread (i changed how I was doing the site)

basically I have a form that takes input from a drop down field asking how many images do you want to upload, which takes you to a new form showing that many file upload fields, each with a radio group beside it, asking you to pick one of 3 possible answers for each upload (3 possible categories for the file uploads to go to)

on the new page it says ok, I got the variables from that, im hoping to have it print out a selector for each that was from the previous page.


So yeh I might be back

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.