Use parameters within a Function, please help me

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BabyBlue

    #1

    Use parameters within a Function, please help me

    I have a function like this:
    function get_articles($c at=1,$numberpos ts=1);

    it can be used:
    get_articles(ca t=4&numberposts =6);
    //will display 6 posts from category 6

    then I want to use that function within another function, like this:

    function display_cat($ne w_cat=1,$new_nu m=1,$otherconte nt="")
    {
    get_articles(ca t=$new_cat&numb erposts=$new_nu m)

    .......
    }


    Can I pass function like this ?

  • lawrence k

    #2
    Re: Use parameters within a Function, please help me

    I have a function like this:
    function get_articles($c at=1,$numberpos ts=1);
    >
    it can be used:
    get_articles(ca t=4&numberposts =6);
    //will display 6 posts from category 6

    You mean

    get_articles(ca t=4, numberposts=6);

    yes?


    then I want to use that function within another function, like this:
    >
    function display_cat($ne w_cat=1,$new_nu m=1,$otherconte nt="")
    {
    get_articles(ca t=$new_cat&numb erposts=$new_nu m)
    >
    ......
    }
    >
    >
    Can I pass function like this ?
    I think you mean

    get_articles($n ew_cat, $new_num);

    And you're not passing a function, you're passing variables. You can't
    pass functions in PHP. You could pass objects, but you don't need to
    here.

    Comment

    • BabyBlue

      #3
      Re: Use parameters within a Function, please help me

      I think you mean
      >
      get_articles($n ew_cat, $new_num);
      >
      And you're not passing a function, you're passing variables. You can't
      pass functions in PHP. You could pass objects, but you don't need to
      here.
      Thank you very much for your reply.

      here is exactly my code:

      $article = get_articles(ca t=4&numberposts =6);
      // then I will extract data from $article

      However, I want to pass 2 parametes cat and numberposts from another
      function, so I must write another function:

      function display_cat($ne w_cat=1,$new_nu m=1,$otherconte nt="")
      {
      $article=get_ar ticles(cat=$new _cat&numberpost s=$new_num)
      ......
      }

      My purpose is want to pass $new_cat and $new_num from function
      display_cat().
      Is is possible ?

      Please help me, thank you very much !

      Comment

      • Pedro Graca

        #4
        Re: Use parameters within a Function, please help me

        BabyBlue wrote:
        I have a function like this:
        function get_articles($c at=1,$numberpos ts=1);
        >
        it can be used:
        get_articles(ca t=4&numberposts =6);
        //will display 6 posts from category 6
        Wrong group?
        This is not PHP; the syntax is wrong.
        For the correct PHP syntax read the manual:


        --
        I (almost) never check the dodgeit address.
        If you *really* need to mail me, use the address in the Reply-To
        header with a message in *plain* *text* *without* *attachments*.

        Comment

        • Michael Fesser

          #5
          Re: Use parameters within a Function, please help me

          ..oO(BabyBlue)
          >here is exactly my code:
          >
          >$article = get_articles(ca t=4&numberposts =6);
          Should be

          $article = get_articles(4, 6);
          >However, I want to pass 2 parametes cat and numberposts from another
          >function, so I must write another function:
          >
          function display_cat($ne w_cat=1,$new_nu m=1,$otherconte nt="")
          {
          $article=get_ar ticles(cat=$new _cat&numberpost s=$new_num)
          Should be

          $article = get_articles($n ew_cat, $new_num);
          }
          Micha

          Comment

          • Jerry Stuckle

            #6
            Re: Use parameters within a Function, please help me

            BabyBlue wrote:
            I have a function like this:
            function get_articles($c at=1,$numberpos ts=1);
            >
            it can be used:
            get_articles(ca t=4&numberposts =6);
            //will display 6 posts from category 6
            >
            then I want to use that function within another function, like this:
            >
            function display_cat($ne w_cat=1,$new_nu m=1,$otherconte nt="")
            {
            get_articles(ca t=$new_cat&numb erposts=$new_nu m)
            >
            ......
            }
            >
            >
            Can I pass function like this ?
            >
            No, you are incorrect. You would call it with:

            get_articles(4, 6);

            "cat=4&numberpo sts=6" is strictly an HTML implementation. It's not used
            within functions like this.

            So in your display_cat function, you would call it with

            get_articles($n ew_cat, $numberposts);

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...