how to use anchor tag in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    how to use anchor tag in php

    like javascript (javascript:and the function) in php how can i use it this is my code:
    [code=php]<?php
    function sorting(){sort( $data);}
    function rsorting(){rsor t($data);}
    $data=array(2,5 6,54,2,32,14,15 4,2184,1214,10, 1,50);
    $num=0;

    while($num<coun t($data))
    {
    echo $data[$num]."</br>";
    $num++;
    }
    ?>
    </head>

    <body>
    <a href="?rsorting ()">Max</a> | <a href="?rsorting ()">Min</a>
    </body>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    You posted this in the PHP Articles forum (despite the gigantic sign that says, "DO NOT POST QUESTIONS HERE"). I'm moving it to the PHP Forum where it might actually get answered :)

    Heya, smartic.

    Couple of issues with your code:
    • Since $data is not global, it is not available to your sorting() and rsorting() functions. You'd have to pass $data as an argument to these functions.
    • sorting() and rsorting() don't return anything, so there would be no output.
    • You can't call a PHP function via an <a> tag. You can link to a PHP page that calls that function, though.
    • To include the output of a PHP function in your HTML, do this instead:

      [code=html]
      <a href="<?php echo sorting(); ?>">Min</a>
      [/code]

      Note though that this will cause sorting() to get executed, and its output will become the href for the <a> tag.

    Comment

    Working...