Jump to content

Passing Two ($_GET) Params in an Array


kvnmck18

Recommended Posts

Link to the XSLT Discussion about this issue.I'm making a photo section on my site, with three Catagories. Each image has an individual ID to pull up the picture. But the problem is when the thumbnail is clicked it opens the picture correctly but then the thumbnails go to the default value (which is "Wedding"). I want it so when I am in the "Theme Parties" when the thumbs are clicked it brings that image up and the Theme Parties thumbs stay.I know how to pass one, but I'm trying to get two $_GET values to pass through a PHP to pull the data from the XML in the XSLT using templates. Both values do work but not together. I can have the .php?page=Value and it brings the right page value up, I can have .php?photo=SomeValue and that works, but if I have .php?page=Value&photo=SomeValue it does not work. So when I make the links include both values it does not work.Here's my current php:
<?php$xmlfile = "xml.xml";$xslfile = "xsl.xsl";if ($_GET['photo']) {$expression= array("photo" => $_GET['photo']);} $args = $expression;if ($_GET['page']) {$expression= array("page" => $_GET['page']);}else {$expression=NULL;}$engine = xslt_create();$output = xslt_process($engine, $xmlfile, $xslfile, NULL, NULL, $args);print $output;xslt_free($engine);?>

I know I canhave the array as:

$expression= array("photo" => $_GET['photo']), ("page" => $_GET['page']);};}

But I don't know how to include both the "ifs" and the "GETs". I'm using PHP4, and I know this would be easily done if PHP5...but that's not an option so I knwo this has to be obtainable through php4.Any ideas? Hope you can help!THank you!

Link to comment
Share on other sites

The only thing I can add is that scince you need both parameters as mentioned, you donn't need the ifs. Only the gets. So remove the whole:

if ($_GET['photo']) {$expression= array("photo" => $_GET['photo']);} $args = $expression;if ($_GET['page']) {$expression= array("page" => $_GET['page']);}else {$expression=NULL;}

and replace it with what justsomeguy already suggested. That is what I was trying to say in the other topic btw.

Link to comment
Share on other sites

Oh, I see what you meant. I guess I misread that. That does work...and thank you very much! Here is the working php XML/XSL with two params:

<?php$xmlfile = "xml.xml";$xslfile = "xsl.xsl";$args = array("page" => $_GET['page'], "photo" => $_GET['photo']);$engine = xslt_create();$output = xslt_process($engine, $xmlfile, $xslfile, NULL, NULL, $args);print $output;xslt_free($engine);?>

...But I guess I want to include the "if" because if the GET is not "Got" then I want it to move to a default value. In this case, if the Get is not Got in reference to the "Page" (?page=) I want it to view all Thumbnails ---Such as if .php was typed. But I don't know how this is possible when the Get for page goes with a Select of the:

<xsl:for-each select="//image[@cat=$page]">...and the only way to make this work would be if the Page default value was "//image[@cat]"...so right now if a value is not present, it does not bring up thumbnails because the select becomes: "//image[@cat= ]".Also the same for the value of the "photo" or in the XML refrence the @id. ".php?photo=&page=Weddings" Brings the thumbs of Weddings and no default value for the <xsl:apply-templates select="//image[@id=$photo]"/>. And in the case of an empty value (no defined value) for the $photo/@id=''/photo I want it to go to the first value listed in the thumbs.BUT A BIG PROBLEM--if the default value of "page" would bring up @cat then the links to the images would still include the .php?page=Value&photo=SomeValue, but when I have the default being at @cat I would want the links just to have .php?photo=SomeValue.I think this is all be done with just a little if added to the php and then call-templates in the xslt. But I'm not quite sure how to get this done... :/
Link to comment
Share on other sites

The PHP kindof like this:

<?php$xmlfile = "xml.xml";$xslfile = "xsl.xsl";if ($_GET['page']) {$expression = array("page" => ."=['".$_GET['page']."']");}else {$expression=NULL;} $args = $expression;else if ($_GET['photo']) {$expression2 = array("photo" => ."=['".$_GET['photo']."']");}else {$expression2=NULL;} $args2 = $expression2;$engine = xslt_create();$output = xslt_process($engine, $xmlfile, $xslfile, NULL, NULL, $args, $args2);print $output;xslt_free($engine);?>

...but that doesn't work.But say if that worked make the XSL call a template when the NULL is called.

Link to comment
Share on other sites

Bla bla bla bla... I didn't understood a thing of your last two posts. But I do realize what you're aiming at anyway. Error handling, which as I mentioned is missing and it's terribly needed.Well, scince the XSLT isn't working good when only one of the parameters is present, but it works with the default values if no parameter is set, then I guess the best thing to do is a single condition to check if both parameters are present and pass both of them or neighter.Simply:

if ($_GET['page'] and $_GET['photo']) {$args = array('page' => $_GET['page'], 'photo' => $_GET['photo']);}

or.... um.... how exactly do to tell if two variables are present? justsomeguy... is the above correct or...?

Link to comment
Share on other sites

If you want to check if a variable has been set, you can use the isset function.

$args = array();if (isset($_GET['page']))  $args['page'] = $_GET['page'];else  $args['page'] = null;if (isset($_GET['photo']))  $args['photo'] = $_GET['photo'];else  $args['photo'] = null;

If you want to tell if a variable has a value, you can use the empty function. Or, if you just check the variable using if ($var) the statement will be false if $var is the empty string, the value false, 0, the string "0", an array with no elements, or the value null, and true otherwise. More about that here:http://www.php.net/manual/en/language.type...boolean.casting

Link to comment
Share on other sites

OK, but that doesn't answer the main question. How to do this check on two variables with one condition? I mean, I understand that two subsequential "if"s will work, but could a single condition check if two variables are set?

Link to comment
Share on other sites

isset checks if the variable has been set. isset($_GET['page']) is true if the $_GET['page'] variable has been set, and false if it has not. If you have this:.php?page=0This will be false:if ($_GET['page'])but this will be true:if (isset($_GET['page']))

Link to comment
Share on other sites

No I know what you meant, but that doesn't mean anything. Because say the "page=" is just defined...but the "id=" is.The defined id would open the picture but leave the page (thumbnail side) incomplete and just empty.

Link to comment
Share on other sites

If you have something like this:.php?page=&id=7Then page will be set, but it will be empty. You can use the empty function to check that, or just check for the empty string:if (!empty($_GET['page']))if ($_GET['page'] != "") that will be true if page is not empty.

Link to comment
Share on other sites

If I have followed all of what justsomeguy says, the code you need is:

if (!empty($_GET['page']) && !empty($_GET['id'])) {$args = array('page' => $_GET['page'], 'photo' => $_GET['photo']);}

or in other words, if both parameters are present and non-empty: set them. Otherwise, leave both of the XSLT values intact.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...