/    Sign up×
Community /Pin to ProfileBookmark

can I call upon multiple functions in single URL?

quick question:

I have a php page with several functions defined on it. I want a link that when clicked, looks for two criteria within my mysql table and displays the results [U]seperately[/U]: filter by “id” to show what is, in this case, a news article, and then below it, show a list of other news articles from the same category as determined by the filter “category”.

So, to do the first half, I’d do this:

[code=php]echo “<div align=left><a href=”{$_SERVER[‘PHP_SELF’]}” .
“?action=showmore&id=$id”><font size=2><b>$date </b> $subject</font></a>” .
“</div>”; [/code]

In this case, “showmore” comes from here underneath SWITCH:

[code=php]case ‘showmore’:
displayAnotherItem($_GET[‘id’]);
break; [/code]

I haven’t been able to figure out to combine the two functions on one page, so I figured I could get the url to call upon both, so at first I expected this to work:

[code=php]echo “<div align=left><a href=”{$_SERVER[‘PHP_SELF’]}” .
“?action=showmore&id=$id?action=catlist&catlist=$catlist”><font size=2><b>$date </b> $subject</font></a>” .
“</div>”; [/code]

Where “catlist” comes from here underneath SWITCH:

[code=php] case ‘catlist’:
displayCatList($_GET[‘category’]);
break;[/code]

But, of course it doesn’t work.

I haven’t been able to find any manuals or tutorials that show what I’m trying to do, despite how basic my desire is. How do I construct the URL? Or am I simply going about this all wrong?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@GarySMay 22.2006 — Don't think you're too far away from what you're traying to achieve.

First thing to do is adjust your query string. Two "actions" in the same string won't work, but you could do something like:

[code=html]"?showmore=1&catlist=1"[/code]

Then you could do things like:

[code=php]if($_GET['showmore']){
// do the showmore
}
if($_GET['catlist']){
// do the catlist
}



[/code]
Copy linkTweet thisAlerts:
@mfaerberauthorMay 22.2006 — [B]EDIT: oh oh, disregard below, I just relized that with the new URL thingy, I'm no longer calling upon the 'action' thingy and so of course I wouldn't put it under that... Think I'm closer now...[/B]


Thanks again for your help Gary!

Don't I need to use "=1" within those "IF"s ?

I'm trying something along these lines (after altering the URL per your recommendation):

[code=php]SWITCH($_GET['action']) {
if($_GET['showmore'] = '1'){
// do the showmore
case 'showmore':
displayAnotherItem($_GET['id']);
break;
}
if($_GET['catlist'] = '1'){
// do the catlist
case 'catlist':
displayCatList($_GET['category']);
break;
}[/code]


But, the page simple won't display anything at all (as if I had an open bracket somewhere). Even if I leave aout the " ='1' " out, it's the same. I'm confused though, because doesn't make sense to me to put these IF statements somewhere else... but it doesn't seem happy with them there...
Copy linkTweet thisAlerts:
@GarySMay 22.2006 — My fault - my last message was unclear. I was suggesting [b]replacing[/b] the SWITCH with a couple of IFs... something like this:


[code=php]if($_GET['showmore'] = '1'){

displayAnotherItem($_GET['id']);

}
if($_GET['catlist'] = '1'){

displayCatList($_GET['category']);
}[/code]


But this won't work yet: the [b]single[/b] equals sign will always evaluate to true. It would work (partially) without the "=1" because...

[code=php]if($_GET['showmore']){

}[/code]


.. tests if $_GET['showmore'] "is true" ... or =1.

BUT (and this is what I messed up first time around) you probably want to test for ISSET. So we have...
[code=php]
if(isset($_GET['showmore']) ){

displayAnotherItem($_GET['id']);

}
if(isset($_GET['catlist']) ){

displayCatList($_GET['category']);
}[/code]



Note that this assumes that [B]showmore [/B]and [B]catlist [/B]appear in the querystring only when required. If they are always present, you need to change the test (i.e., to examine their value).
Copy linkTweet thisAlerts:
@mfaerberauthorMay 22.2006 — Awsome, I think I understand this now, thanks again for your help Gary.

So I converted everything that was under SWITCH to use IF and ISSET and there's still a lot more I have to do with this, but you've helped me get a good start.

I question does remain at the moment though, before, under the SWITCH section, there was this case at the end:
[code=php] default:
displayNews();[/code]

Of which, refered back to:
[code=php] case 'all':
displayNews(1);
break;[/code]

Now, for my new ISSET section, I have this:
[code=php]if(isset($_GET['all']) ){
dislplayNews(1);
}[/code]

I have a top link that utilizes the code under displayNews (its the main page), so I tried tacking "?all=1" onto the end of the "newspage.html" URL, but that doesn't work (everything on the page works and is displayed up until the spot where the "newspage.html", a seperate include, should show up). I'm not sure why this doesn't work or what I'm supposed to do...
Copy linkTweet thisAlerts:
@GarySMay 22.2006 — Two little things (that may we just be typos in your post):

[list]
  • [*] dislplayNews(1); //typo??

  • [*] If you're tacking onto the end of a query string, make sure it's "[B]&[/B]all=1"

  • [/list]


    You could also avoid the extra query string elements and test for "the lack of the other elements" (analogous to the default condition in the SWITCH)

    [code=php]if( !isset($_GET['showmore']) && !isset($_GET['catlist']) ){

    displayNews(1);

    }[/code]
    Copy linkTweet thisAlerts:
    @mfaerberauthorMay 22.2006 — Well, the first part of the displayNews function went a little something like this:
    [code=php]function displayNews($all = 0) {
    @include("custid.html");
    global $db, $max_items;

    /* query for news items */
    if ($all == 0) {
    /* this query is for up to $max_items */
    $query = "SELECT...[/code]


    I set the $max_items earlier on so I can tell it how many news items I want it to show on this particular page.

    Anyways, I'm good for now after using your last suggestion. I ended up doing a combination of SWITCH and the IF statements to get everything to jive. Thanks for all your help!
    ×

    Success!

    Help @mfaerber spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.12,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...