PHP is a bit complex! Been spending ages trying to figure this out where: <? if ($_GET["setID"] != "" && $_GET["modelID"] != "") { ?> Code (markup): Hope anyone can help?
I get this: Fatal error: Cannot use [] for reading What I want to do is allow a view for (index.php) ?setID=x AND ?modelID=x only...
It can be set AND empty, you should check for BOTH... you also should be using "empty", not =="" if ( isset($_GET['setID']) && !empty($_GET['setID']) && isset($_GET['modelID']) && !empty($_GET['modelID']) ) { Code (markup): Again, they can be set and empty, so you have to check BOTH. (I really wish they had a check for both as a single operation) ... and for ghu's sake, stop opening and closing PHP on every line like that
Nope none of them work for displaying it for setID and modelID. This works in that it doesn't display it for the categories page...not sure what's going on: <? if ($_GET["categoryID"] == "") { ?> Code (markup):
Uhm... what EXACTLY are you actually trying to do? I have the feeling you aren't showing us enough code or explaining what it is you are actually trying to do.... Should that even be an AND? You realize that && would require all conditions to be true to run the code inside the {}, right? Should they be separate IF for testing two different values? Should it be an OR? (unlikely in my mind)... Could we see the form your getData is coming from? I think we just need to see more to figure out what you are trying to do.
Sorry guys, yes you're right. Here's the exact code below (apologies for opening/closing the tags so much...). The get call is all coming from one page, i.e.: index.php?setID=SETNAME index.php?categoryID=CATEGORY I'd only want the code below to be live on the setID and CategoryID pages only, which is currently: (* <? if ($_GET["categoryID"] == "") { ?> is what I'm looking to change *) <? if ($_GET["categoryID"] == "") { ?> <div id="secondarynav"> <? include("inc-breadcrumbs.php"); ?> <? if ($_GET["setID"] != "") { ?> <span class="socialstuff"><a href="/"><img src="images/love-add.png" alt="test" /></a> <a href="/"><img src="images/love.png" alt="test" /></a> <a href="/"><img src="images/Facebook.png" alt="test" /></a> <a href="https://www.pinterest.com/join/?next=/pin/create/button/%3F"><img src="images/Path.png" alt="test" /></a> <img src="images/Reddit.png" alt="test" /> <a href="/"><img src="images/StumbleUpon.png" alt="test" /></a> <a href="/"><img src="images/Twitter.png" alt="test" /></a></span> <? } ?> </div> <? } ?> Code (markup):
Well, that's kind-of a confusing mess thanks to all that malfing opening and closing PHP for no good reason, but translating it to this: if (isset($_GET['categoryId']) && !empty($_GET['categoryId'])) { echo ' <div id="secondarynav">'; include("inc-breadcrumbs.php"); if (isset($_GET['setID']) && !empty($_GET['setId']) { echo ' <span class="socialstuff"> <a href="/"> <img src="images/love-add.png" alt="test" /> </a> <a href="/"> <img src="images/love.png" alt="test" /> </a> <a href="/"> <img src="images/Facebook.png" alt="test" /> </a> <a href="https://www.pinterest.com/join/?next=/pin/create/button/%3F"> <img src="images/Path.png" alt="test" /> </a> <img src="images/Reddit.png" alt="test" /> <a href="/"> <img src="images/StumbleUpon.png" alt="test" /> </a> <a href="/"> <img src="images/Twitter.png" alt="test" /> </a> </span>'; } echo ' <!-- #secondaryNav --></div>'; } Code (markup): Should be what you are trying to do -- assuming you only want setID showing when categoryID is also true. Really some formatting and easing up on the endless pointless <? ?> for nothing would REALLY help make your logic clearer.
I got an error, so I'm thinking this line should be: if (isset($_GET['setID']) && !empty($_GET['setID'])) { Code (markup): - But still didn't work, the <div id="secondarynav">xx</div> stuff isn't on any pages now...
Ok I saw the problem categoryId = categoryID works now. However, how do I include setID on this line as this doesn't work for the setID, categoryID and modelID pages: <? if (isset($_GET['categoryID']) && !empty($_GET['setID']) && isset($_GET['setID']) && !empty($_GET['categoryID']) && isset($_GET['modelID']) && !empty($_GET['modelID'])) { Code (markup):
Are you sure you want all of those conditions to be true at the same time? Any one of them fails, none of them will run...
Yep..I'd like it to be for those conditions only or should I use ! for the non-conditions which are: index.php index.php?site=about
Again, I'm just really not clear on what you are even asking... and not certain you understood what I asked either. Need to see more of it as in what are you actually trying to do here?
From what I understand: (isset($_GET['categoryId']) - Show if there's ?categoryID=SET && !empty($_GET['categoryId']) - Show if there's nothing set for ?categoryID. So I'd like to include setID and modelID conditions in that line, so it shows the code on these pages with setID and modelID on...
THIS: (isset($_GET['categoryID']) && !empty($_GET['setID']) && isset($_GET['setID']) && !empty($_GET['categoryID']) && isset($_GET['modelID']) && !empty($_GET['modelID'])) Will only work if ALL of them are SET at the same time -- I think that's what you are missing here. As such whatever you are testing for would only work if for example: ?categoryID=something&setID=somethingElse&modelID=someOtherBlastedThing ALL of them AT ONCE. That would work out to true. This: ?categoryID=something&setID=somethingElse Would be false. As would: ?categoryID=something&modelID=someOtherBlastedThing and: ?setID=somethingElse&modelID=someOtherBlastedThing None of those would pass the test. Is that what you are trying to do? I have the feeling you either should be testing for 'or' instead. (|| instead of &&) or you should be breaking that into multiple separate conditions. Again, you aren't showing us enough of what you are doing with the result or where it's coming from for a reasonable answer to be given.
Sorry for the headache! Yep it's || I should of used instead of && - thanks everyone for taking time out on this.
Just be sure to pair your isset and empty with && when doing that. That's one reason I like to format as multiple lines to make it easier to follow, and pair them by variable instead of operation. if ( (isset($_GET['categoryID']) && !empty($_GET['categoryID'])) || (isset($_GET['setID']) && !empty($_GET['setID'])) || (isset($_GET['modelID']) && !empty($_GET['modelID'])) ) { Code (markup): Since you want to make sure it's set (so you can work with them) and not empty... and beware that inside your routine you still can't be sure if they are set or not, which is why what you are doing inside that condition is important too. Also important is evaluating the && before each ||, hence the extra parenthesis to imply specificity / evaluation order.
oh, and when you get this deep into parenthesis and logic, an editor that highlights matching pairs of brackets and parenthesis can REALLY help. One of the few editor "aids" I actually like.